How to clean cache like THREE.Cache.clear();

Is there any cache clean function in playcanvas?

My script just clone the avatar and destroy when I click the button.
But It seems to be there are some memory leak, so I want to refresh the memory when destroy clones.

This is my code.

var CloneTest = pc.createScript('cloneTest');
var d;

// Initialize code called once per entity
CloneTest.prototype.initialize = function() {

    // Register the mouse down and touch start event so we know when the user has clicked
    start_as ="Button_as");
    pause_ax ="Button_ax");
    stop_ax ="Button_ad");;
    count_a ="avatarcount")[0].element;


    start_as.button.on('click', function(event){
        if(event.button == pc.MOUSEBUTTON_LEFT){
                        console.log("clone start! " + "Avatar:  " + f.length);

        if(event.button == pc.MOUSEBUTTON_LEFT){
    }, this);

    }, this);

        if(event.button == pc.MOUSEBUTTON_LEFT){
    }, this);

    }, this);


CloneTest.prototype.TestClone = function(event) {

        cloned ="POC_dance");
        e = cloned.clone(); // Clone Entity
    } else if (d == false){

CloneTest.prototype.DeleteClone = function(event) {

    for (var k = f.length - 1; k >= 1; k--) {[k];
        r.destroy(); // destroy Entity

Do you have a project example where the leak can be seen? In the code posted above, I can’t see where memory would be allocated to have the memory leak.

This is my project :slight_smile:

Can you explain the steps to produce the leak and also how you are seeing that there is one please?

My project is working as below.

  1. Start : clone the avatar.
  2. Pause : stop the cloning.
  3. Stop : destroy the avatar.

I can see the memory leak throw the Performance monitor of chrome.
If I click the stop button to destroy the avatar, I can see the CPU usage is initialized, but the JS heap size is not initialized.

How do you do these steps in the app, all I have are:

Can you give me a list of very specific steps of which buttons to press and in which order please?

It works fine for me.

I use memory tab in chrome to monitor the memory. I am around 20-25 Mb when applicaiton started. I click start and the app starts to make clones. The memory grows to 100+ Mb when I have some 100 clones. I press pause and stop. Clones are cleared and after a few seconds the memory returns back to 20-25 Mb.

I noticed only the first “cycle” is ok. If you start cloning again, without refreshing it, it will clone double, almost immediately. On the next cycle, it will clone tripple, or 3 times at a time. There is an issue with your code, probably a timer not cleared or something. Doesn’t affect the memory though, as it is cleared for me after pause and stop.

1 Like