Android : References to a Context and memory leaks

前端 未结 2 2027
误落风尘
误落风尘 2020-12-04 18:18

I\'ve read that it is a mistake and a source of memory leaks in Android application to keep a long-lived references to a Context.

But I don\'t understand if it is ok

2条回答
  •  渐次进展
    2020-12-04 18:48

    The scope of the HelperClass is only within your onCreate function, so once onCreate executed, your "h" object is no longer needed and subject to garbage collection.

    It would be a different story if "h" was a static member - THAT would be a great way to leak memory.

提交回复
热议问题