Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phaser.Cache.destroy() does not destroy cached items #68

Closed
andrekampert opened this issue Mar 22, 2017 · 3 comments
Closed

Phaser.Cache.destroy() does not destroy cached items #68

andrekampert opened this issue Mar 22, 2017 · 3 comments
Assignees

Comments

@andrekampert
Copy link

This Issue is about a bug in the Phaser.Cache API 2.7.3 and below.

In method Phaser.Cache#destroy

/**
 * Clears the cache. Removes every local cache object reference.
 * If an object in the cache has a `destroy` method it will also be called.
 *
 * @method Phaser.Cache#destroy
 */
 destroy: function () {
   // ...
}

The unexpected behaviour is that most objects that are put in the cache are wrapped in another object, without a destroy method.

For example, looking at BitmapData, which has a `destroy' method:

  • addBitmapData stores the actual data in a new object with keys data and frameData
  • getBitmapData relies on getItem to get the correct data from the cache
  • destroy does not take the property into account as getItem does and therefore does not invoke destroy on the data and frameData objects.

As a result, in this case, canvasses are never returned to the CanvasPool, causing a memory leak when loading external image data and relying on the cache to clean up old images.

Suggested solution:

  • Update the destroy method to also iterate over the properties in the stored cache object. If a property contains a destroy method, invoke it on the property as well.
@samme
Copy link
Collaborator

samme commented Mar 26, 2017

Hi @andrekampert, can you test: phaser-test.js.zip

@samme
Copy link
Collaborator

samme commented Mar 27, 2017

samme@0006372

@andrekampert
Copy link
Author

This makes a huge difference. The retained object size in our scenario is reduced to 1/10th of the amount used without the change, mainly due to the canvas pool being cleared correctly now.

Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants