MainActivity leaked using leakcanary

不羁的心 提交于 2019-12-13 11:37:51

问题


I am using Leak Canary to track memory leak and it says the following were leaked:

static hk.o 
references ht.a 
leaks MainActivity instance

what is the hk.o and ht.a? I dont have them in my MainActivity.


回答1:


Those classes are third party library classes . You may take your MainActivity instance as an argument and pass in which class's instance belong to library. You could use ApplicationContext as an argument if it's not necessary to pass in Activity.




回答2:


I think those are pro guarded (renamed classes with random names to prevent reverse engineering) of any one of the dependencies. I have seen this when stuff related like Google Sign In is used in the app.

Google Services classes are generally Pro Guarded.

I hope this helps.




回答3:


I tracked this down, and the culprit is Google Ads. The classes you mentioned are actually from the library com.google.ads.interactivemedia.v3:interactivemedia, which is included with play-services-ads.

The reference to the activity was set via the constructor of PublisherAdView, where I passed the activity context. Probably you are also using a similar ad view in your app.

As a workaround, I now pass the application context to the ad view, which seems to have solved the leak:

new PublisherAdView(getContext().getApplicationContext())


来源:https://stackoverflow.com/questions/42464429/mainactivity-leaked-using-leakcanary

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!