Skip to content

Can't understand why a memory leak happens #1

Description

@onemonster

Hi, I was interested in this sample after finding a link to it on stackoverflow and I was wondering if you can make things more clear for me. The link to the blog was broken.

stackoverflow link
https://stackoverflow.com/questions/28539216/android-textview-leaks-with-setmovementmethod

In this link you stated that onSaveInstanceState() is called after onStart() so that the spannable string must be set up there and not in the onCreateView() method. Since onStart() is called after onCreateView() I don't see what difference this will make. You said the problem is that the spannable string is replaced with the old copy creating problems.

  1. If the old copy replaces the new copy, how does this create a leak? There are no variables referencing the new spannable string if the old copy replaces its' spot.
  2. If the old copy replaces the new copy in onSaveInstanceState() and onSaveInstanceState() is called after onStart(), doesn't it replace it even if we set the spannable string in onStart()? How is this different from onCreateView().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions