MainActivity leaked using leakcanary

2019-03-23 22:35发布

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.

3条回答
虎瘦雄心在
2楼-- · 2019-03-23 23:07

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())
查看更多
等我变得足够好
3楼-- · 2019-03-23 23:14

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.

查看更多
狗以群分
4楼-- · 2019-03-23 23:17

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.

查看更多
登录 后发表回答