-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Fix memory leak in SimplePaletteItem #3202
base: master
Are you sure you want to change the base?
Conversation
For some reason, App Inventor was creating 2 instances of components every time a component was being dragged. However, the extra instance was not being deleted or cleaned up, losing access to the instance as no pointer was ever referring to it again.
@@ -127,7 +127,7 @@ public MockComponent createMockComponent() { | |||
cacheInternalComponentPrototype(); | |||
|
|||
MockComponent returnedComponentPrototype = componentPrototype; | |||
componentPrototype = null; | |||
// componentPrototype = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this code does not 100% work (it stops creating some new instances), but just sharing it as something's off with the actual component instantiation. 🙂
Every time a component gets dragged and dropped, two instances are created but just one fires its delete
.
Thanks Diego. I'm not sure why the second instance isn't being GCed but if this resolves the memory pressure that's definitely helpful. Sent from my iPhoneOn Jul 15, 2024, at 15:47, Diego Barreiro Perez ***@***.***> wrote:
@barreeeiroo commented on this pull request.
In appinventor/appengine/src/com/google/appinventor/client/editor/simple/palette/SimplePaletteItem.java:
@@ -127,7 +127,7 @@ public MockComponent createMockComponent() {
cacheInternalComponentPrototype();
MockComponent returnedComponentPrototype = componentPrototype;
- componentPrototype = null;
+ // componentPrototype = null;
I know this code does not 100% work (it stops creating some new instances), but just sharing it as something's off with the actual component instantiation. 🙂
Every time a component gets dragged and dropped, just two instances are created but just one fires its delete.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
I also made a Memory Heap Profile from Chrome, to validate whether the objects are being retained, and indeed they are. Took 3 different snapshots:
Between 1 and 2, you can see there is a +2 delta of Between 2 and 3, there is a -1 delta of I did also repeat the same test with the same instance, just to maybe assume that a new "extra" one was not being created if I dropped "again" the However, it seems to not be a global issue, but related to some specific components. I did the same test with Could it be an issue with |
In |
Could be. If that creates a reference somewhere, the GC may think that it is still being used so it doesn't get cleaned up. I was investigating a couple of things, and despite some components are in fact being cleaned up by the GC, they don't trigger the |
For some reason, App Inventor was creating 2 instances of components every time a component was being dragged. However, the extra instance was not being deleted or cleaned up, losing access to the instance as no pointer was ever referring to it again.
Tracing down this variable's usage, it seems to be restricted to this file, and no further usage of the "extra" component is being made. This code has been in AI2 since 2011, without major updates besides 2018 and 2023 being the most recent updates.
The current flow was:
createMockComponent
was invoked when the user started dragging the component. The created component resets its reference, henceSimplePaletteItem
thinks it was not yet initialized.isVisibleComponent
to be triggered, and it creates another instance. This new instance is now preserved.See below the debug logs:
Two
createMockComponentFromPalette
events are triggered for the components, but just a single one triggers itsdelete
method. One of the copies is left in memory somewhere, which would cause "long development sessions" to become laggier as those components are not cleaned up.