Skip to content
This repository has been archived by the owner on Jul 28, 2020. It is now read-only.

memory leak #413

Closed
underworld9 opened this issue Nov 2, 2018 · 6 comments
Closed

memory leak #413

underworld9 opened this issue Nov 2, 2018 · 6 comments
Labels
bug Something isn't working fixed in upcoming release

Comments

@underworld9
Copy link

I have found a memory leak when closing a session. (stopping & destroying the arCore activity)
found using the Android Profiler.
There are some objects with names like "bkm", "big", "bff", etc. that get increased by 2 after a session was opened. So after opening a session 7 times these objects have an allocation count of 14.

after_opening_session_one_time
after_opening_session_seven_times

I have tested this Memory Leak in several different ArCore samples.
new samples and older ones.
the Memory Leak happens in every single one of them! every time the Activity is destroyed.
it never happens if the Activity is saved and stopped.
i also have created an App that does nothing except
set the content view to: com.google.ar.sceneform.ux.ArFragment
and the Memory Leak happens every time.

every session increases the memory by an average of 3,5 MB.

@claywilkinson
Copy link
Contributor

Thanks for the details. We'll take a look.

@claywilkinson claywilkinson added the bug Something isn't working label Nov 7, 2018
@codeniko
Copy link

I'd like to add to this which might be relevant. I'm seeing StrictMode violation and that my activity has leaked android.widget.FrameLayout. I'm not using FrameLayout at all on my side, but I do see that ArFragment extends BaseArFragment which does hold a reference to one. I'm guessing that's where the leak is.

This is what I see every time I rotate screen (I do not wish to disable this). I've also tried using WeakReference for holding my ArFragment reference, same thing. I'm using sceneform 1.5.1

2018-11-27 13:50:53.483 23233-23233/com.nfeld E/StrictMode: class com.nfeld.ar.ArSceneActivity; instances=2; limit=1
    android.os.StrictMode$InstanceCountViolation: class com.nfeld.ar.ArSceneActivity; instances=2; limit=1
        at android.os.StrictMode.setClassInstanceLimit(StrictMode.java:1)
2018-11-27 13:50:53.496 23233-23233/com.nfeld E/WindowManager: android.view.WindowLeaked: Activity com.nfeld.ar.ArSceneActivity has leaked window android.widget.FrameLayout{114fb77 V.E...... ......I. 0,0-0,0} that was originally added here
        at android.view.ViewRootImpl.<init>(ViewRootImpl.java:614)
        at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:365)
        at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:100)
        at com.google.ar.sceneform.rendering.ViewAttachmentManager.lambda$onResume$0$ViewAttachmentManager(ViewAttachmentManager.java:64)
        at com.google.ar.sceneform.rendering.ViewAttachmentManager$$Lambda$0.run(Unknown Source:2)
        at android.os.Handler.handleCallback(Handler.java:789)
        at android.os.Handler.dispatchMessage(Handler.java:98)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6938)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

@malik-at-work
Copy link

I am able to reproduce this leak. I'll work on a fix.

@malik-at-work
Copy link

I've fixed this in our codebase. This did not make the 1.6.0 release train however so will be in a release after that.

claywilkinson added a commit to claywilkinson/sceneform-android-sdk that referenced this issue Dec 11, 2018
Reported as google-ar#413
The ViewTreeObserver & listener kept a reference to the fragment after the view & activity were destroyed.
@claywilkinson
Copy link
Contributor

Here is the Pull Request if you want to build an updated version of the ux library.
#461

@underworld9
Copy link
Author

underworld9 commented Feb 18, 2019

@malik-at-work @claywilkinson
I can confirm that 1.7 has fixed a memory leak.
thank you!
however when i tested this i still saw different objects that increase by 1 every session.
this is obviously a different memory leak.
i have created a follow up Issue about this: #538

claywilkinson added a commit to claywilkinson/sceneform-android-sdk that referenced this issue Dec 24, 2019
Reported as google-ar#413
The ViewTreeObserver & listener kept a reference to the fragment after the view & activity were destroyed.
@ChanduMnS ChanduMnS mentioned this issue Apr 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working fixed in upcoming release
Projects
None yet
Development

No branches or pull requests

5 participants
@codeniko @claywilkinson @malik-at-work @underworld9 and others