mobile-sdk-ios icon indicating copy to clipboard operation
mobile-sdk-ios copied to clipboard

AppNexus SDK causing memory leaks (`createOMIDAdSessionforNative`)

Open marcin-bo opened this issue 3 years ago • 14 comments

We have noticed memory leaks related to AppNexus SDK. It happens with the latest SDK (7.11) and previous one as well. After several ad requests, in few minutes, the memory usage jumps from ~100MB to over 500MB and the test device heats very much. On our side (the integration) it seems that everything is retained correctly.

We have been able to narrow the issue to the registerOMID function inside ANNativeAdResponse.m, specifically line 191:

self.omidAdSession = [[ANOMIDImplementation sharedInstance] createOMIDAdSessionforNative:self.viewForTracking withScript:scripts];

The above line probably creates some retain cycles and memory leaks.

Setting the enableOpenMeasurement flag to false on app start solves the issue. However, as we correctly understand the consequences of such change we cannot do it (limited tracking).

Could you please fix those memory leaks?

marcin-bo avatar Apr 08 '21 12:04 marcin-bo

Hi @marcin-bo,

Can you post your Memory Graph(or some other logs/screenshot) showing what object is causing this memory retain cycle.

We have some changes going out in the next sdk release(v7.12) which fixes Views registered with the SDK for Native Ads are getting retained. Want to make sure if you are also facing the same issue or its something different.

Thanks and BR, Kowshick S

Kowshickkarthick avatar Apr 08 '21 15:04 Kowshickkarthick

Actually I haven't detected anything weird in memory graph :/

The only clue is that the following line fixes the issue:

ANSDKSettings.sharedInstance().enableOpenMeasurement = false

Maybe we will test it after you release 7.12. When do you plan to do it?

marcin-bo avatar Apr 09 '21 14:04 marcin-bo

7.12 should be released sometime next week. Will let you know when the release is out.

Kowshickkarthick avatar Apr 09 '21 16:04 Kowshickkarthick

I can confirm the same issue, we are experiencing seriously degraded performance while scrolling on React Native using Xandr SDK as a native UI component. Setting [ANSDKSettings sharedInstance].enableOpenMeasurement = false; solves it.

danieltovesson avatar Apr 12 '21 06:04 danieltovesson

HI @danieltovesson, v7.12 has been released. Can you check and let us know if the issue is fixed or you are still facing the issue.

Kowshickkarthick avatar Apr 19 '21 15:04 Kowshickkarthick

Hi @Kowshickkarthick. Unfortunately, we don't see any big improvements. Have you tried updating @marcin-bo?

danieltovesson avatar Apr 26 '21 12:04 danieltovesson

Hi @Kowshickkarthick . We don't see any improvements as well :(

marcin-bo avatar Apr 27 '21 05:04 marcin-bo

Hey @danieltovesson, @marcin-bo, We identified that the SDK was holding a strong reference to the view that was not owned by the SDK & hence creating retain cycles. We resolved the same in v7.12.

Can you post the profiler map & the memory graph to show which object is holding more memory?

Also, can you give more details like how many native ads do you load on-page & how frequent is the refresh?

ppuviarasu avatar Apr 27 '21 11:04 ppuviarasu

@ppuviarasu Hi, I am noticing the same issue. Running with 7.13 now. It works fine if I set OpenMeasurement to false, but when it's true the Memory increases drastically for each page view.

We requests 2 native ads per page view, and user can swipe horizontally between pages unlimited number of times to load new page views.

lindanordstrom avatar May 19 '21 11:05 lindanordstrom

Hi @ppuviarasu ,

Hey @danieltovesson, @marcin-bo, We identified that the SDK was holding a strong reference to the view that was not owned by the SDK & hence creating retain cycles. We resolved the same in v7.12.

Can you post the profiler map & the memory graph to show which object is holding more memory?

I couldn't generate memory graph because debugger crashes everytime I try to do it :(

Also, can you give more details like how many native ads do you load on-page & how frequent is the refresh?

We have a collection view with one or two or three ads (depending on user type). Memory usage drastically increases in two cases:

  1. When we switch few times to other screen and get back to the screen with collection view.
  2. Or when we scroll the collection view up and down few times.

Setting the enableOpenMeasurement flag to false on app start solves the issue.

marcin-bo avatar May 19 '21 12:05 marcin-bo

And further details:

1. When we switch few times to other screen and get back to the screen with collection view.

Everytime we enter the screen, we make a native ad request (recently we updated to use multi ad request).

2. Or when we scroll the collection view up and down few times.

Everytime the cell is displayed in such case we load native ad response from in-memory cache (which is invalidated when user leaves the screen).

marcin-bo avatar May 19 '21 12:05 marcin-bo

Hi All, We have upgraded to the new version of OMSDK(1.3) on our SDK v7.15. Can you confirm if the issue is resolved for us to close the same?

ppuviarasu avatar Aug 19 '21 16:08 ppuviarasu

We have updated to 7.17. The updated SDK does not solve the issue - still memory leaks. And setting the enableOpenMeasurement flag to false on app start solves the issue.

marcin-bo avatar Sep 07 '21 12:09 marcin-bo

The leak still seems to be there for 7.20.0 as well.

WouterWisse avatar Feb 25 '22 11:02 WouterWisse