Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Possible Memory Leaks and missing onDestroyView cleanup #933

Description

@MasterEmit

Just read some discussion about the problem with fragments, that a missing cleanup of view references can cause a memory leak.

http://stackoverflow.com/questions/13421945/retained-fragments-with-ui-and-memory-leaks

I checked the generated classes of android annotations and could not find any place, where views will be cleaned. We are able to see, that just switching fragments increases memory usage. We will try to write a small cleanup ourself shortly, but maybe it would be great to implement it at android annotations.

Activity

  1. yDelouis commented on Mar 26, 2014

    @yDelouis
    Contributor

    If I understand the post correctly, the memory leak happens only if you call setRetainInstance(true) on the Fragment.
    AndroidAnnotations doesn't generate this call. So, I don't think it shouldn't be responsible for cleaning up Views in onDestroyView.

  2. bastienvalentin commented on May 6, 2014

    @bastienvalentin

    Hi,
    I'm currently working on a project using android annotation 3.0.1. As far as I know I'm not using the retainInstance method with a true value. On the other hand I'm using the addToBackstack method in order to have a correct user navigation when the user press back.
    My problem is an out of memory error which may be caused by the non-implementation of the onDestroyView of the fragment. Indeed when I'm on the fragment A, going to the fragment B and then going back to the fragment A using the back button (and so the backStack) I can see that this fragment is not destroyed as well as the view inside it. In my case this results in a memory leak.
    To solve the bleeding I'm forced to directly edit the generated file and override the onDestroyView in order to put the contentView_ to null and clean the memory a bit.
    I may be mistaken but I think that this method should be override by android annotation.
    If I'm mistaken please let me know.
    Kind regards.

  3. WonderCsabo commented on May 6, 2014

    @WonderCsabo
    Member

    So if you set all the injected View fields in onDestroyView, the Fragment does not leak, but if you just leave the generated code as is, the Fragment stays in memory?

    @yDelouis Maybe we should clear the fields anyway, since the client code can call setRetainInstanceState(true), but it has no chance cleaning up the Views because they are in the generated subclasses.

  4. yDelouis commented on May 6, 2014

    @yDelouis
    Contributor

    It doesn't cost so much so yes, we should.

  5. nenick commented on May 6, 2014

    @nenick

    Nice to hear about that. I'm facing the same issue with growing memory.

    But also we should look if that a mistake by our own app implementations.

    Currently I'm working on a simple project template with aa and just there I see growing memory usage when switching between activities.

    You can also reproduce it with simple app sample? When not I will just search the error in my code.

  6. bulatgaleev commented on Jul 17, 2014

    @bulatgaleev

    Any update on this?

  7. WonderCsabo commented on Aug 22, 2014

    @WonderCsabo
    Member

    Feel free to contribute the feature. :)

  8. bulatgaleev commented on Aug 22, 2014

    @bulatgaleev

    In progress already:)

  9. WonderCsabo commented on Aug 22, 2014

    @WonderCsabo
    Member

    Great, thanks for your contribution! If you need any help on the implementation, just let us now.

  10. DayS commented on Sep 21, 2014

    @DayS
    Contributor

    @LocalHostEu What's the status of your work on this ?

  11. bulatgaleev commented on Sep 22, 2014

    @bulatgaleev

    @DayS Still need some time to finish.

  12. WonderCsabo commented on Sep 29, 2014

    @WonderCsabo
    Member

    Cleaning the contentView_ reference is now merged. We will also clean the injected View fields, but that will be in the next major release (4.0), because that is a breaking change.

  13. WonderCsabo commented on Jun 10, 2015

    @WonderCsabo
    Member

    Finally fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions