-
Notifications
You must be signed in to change notification settings - Fork 5
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
Dispose tandems when disposing phetioGroup Element #264
Comments
Great catch @marlitas! Let me do some explaining. Tandems are already set up to be "monolithic" in the sense that only one instance of Tandem should exist for a given phetioID. Thus, if you createTandem to make something that already exists, createTandem() will just return that instance instead of creating a duplicate instance. See here: Lines 246 to 256 in ddd87c9
For dynamic elements, we do the same logic, where we re-use tandems if available (most often they aren't though, like you in your case where they have already been disposed, but we'll get to that): tandem/js/PhetioDynamicElementContainer.ts Lines 266 to 272 in 0dc0a12
So much of my investigation here was confirming that DynamicTandems are supported in that same way, and shouldn't just be re-created each time a new element is made. The same goes for disposal. We don't necessarily need to dispose it manually for dynamic elements, because it should be disposed automatically if it has no more children etc. The issue was that when disposing the child, we were cutting the parent off from the child, but not the child from the parent. Thus the child, though disposed, still had a reference to the parent, and thus wouldn't get garbage collected. I believe this solves you leak. Please review. |
Most likely this changed is causing phetsims/natural-selection#311 (comment). I think we have to do a better job of setting the parentTandem once using that instance again. |
… already been deleted by next frame, phetsims/natural-selection#311 #264
Just a small extra step in making sure we don't do API validation on disposed elements. |
This got fixed when we moved to static allocation: phetsims/mean-share-and-balance#60 |
While working on Mean: Share and Balance @samreid and I noticed a memory leak that involved tandem and dynamicTandem.
To recreate:
Upon further investigation we added
element.tandem.dispose();
toPhetioDynamicElementContainer.ts
line 355 ( inside disposeElement function). This eliminated the tandem leak.Before fully implementing this change we wanted to check with @zepumph to make sure this wouldn't waterfall into affecting other phetio functionality negatively.
The text was updated successfully, but these errors were encountered: