Unity iOS banner ads appear to leak memory and appear where it shouldn't

132 views
Skip to first unread message

EdB

unread,
Jul 6, 2016, 6:31:41 PM7/6/16
to Google Mobile Ads SDK Developers
Hi - I'm testing out the Unity plugin for Google Mobile Ads v3.0.4 (using GoogleMobileAds.framework 7.8) on Unity 4.7.2, building for iOS onto an iPhone4.

I'm using Instruments/Activity Monitor/Real Memory to monitor ram usage of my game and noticed that after a banner ad is played and then destroyed (after a new scene is loaded)
that there's some extra memory being used by the banner that never gets freed.  This keeps increasing to a higher amount every time I enter and leave the scene with the banner ad in it.

Also - the banner ad can pop on in a scene where there is no reference the banner object!  Nothing references the banner ad outside of the scene it gets created in.

It gets destroyed in the scene it is created in here:

    void OnDestroy()
   
{
       
if (bannerView != null)
       
{
            bannerView
.Destroy();
       
}
   
}



It gets created one time in Start() here:

    bannerView = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Top);
       
   
// Register for ad events.
    bannerView
.OnAdLoaded += HandleBannerAdLoaded;
    bannerView
.OnAdFailedToLoad += HandleBannerAdFailedToLoad;
    bannerView
.OnAdLoaded += HandleBannerAdOpened;
    bannerView
.OnAdClosed += HandleBannerAdClosed;
    bannerView
.OnAdLeavingApplication += HandleBannerAdLeftApplication;
       
   
// Load the banner with the request.
    bannerView
.LoadAd( GlobalStuffManager.Inst.CreateAdRequest() );

    bannerView
.Show();


Any ideas?  Maybe it's something to do with arc?  Automatic Reference Counting is disabled for my Xcode project by default...is that an issue?

Thanks for any help! 

Veer Arjun Busani(Mobile Ads SDK Team)

unread,
Jul 7, 2016, 10:52:44 AM7/7/16
to Google Mobile Ads SDK Developers
Hi there,

Before I even dwell into trying to reproduce the issue, is there a reason why you have not enabled ARC in your project? Since the plugin was built on the assumption that ARC is enabled, if you want to continue to use MRR, then you would have manually edit a lot of classes for the plugin. One good place to start is in the iOS folder for the Mobile Ads Plugin in Unity. I, however would not be able to provide any support on how to go about this.

Thanks,
Veer Busani
Mobile Ads SDK Team

EdB

unread,
Jul 7, 2016, 8:38:33 PM7/7/16
to Google Mobile Ads SDK Developers
I didn't specify anywhere in my project to use or not use arc...maybe some plugin is turning it off. I'll investigate.

EdB

unread,
Jul 8, 2016, 4:32:29 PM7/8/16
to Google Mobile Ads SDK Developers
I did a test build with Unity 4.7.2 of an empty project.  The resulting XCode project defaulted to build settings with ARC set to NO.

Then I went back to my original project that I asked the question about.
I manually set use ARC to YES and compiled the project (after having to set the compile flags several other .mm files to -fno-objc-arc.) 
After profiling this build on an iPhone4 and an iPhone 5s, memory still didn't ever seem to be freed from banner ads and interstitial ads,

I noticed that since I'm not using Unity 5, there's a bunch of properties that don't get set when PostProcessor.cs runs...I just get the
message "Unable to modify build settings in XCode project.  Build settings must be set manually."  Wondering if this could be a factor...

Also - I'm using XCode Version 7.2.1.

Veer Arjun Busani(Mobile Ads SDK Team)

unread,
Jul 8, 2016, 5:10:26 PM7/8/16
to Google Mobile Ads SDK Developers
Hi there,

Is there a reason why you are not on the latest Unity build? It would not be valid to check with an older version how memory is being handled. I just did some profiling with the latest Unity 5.3.5f1 and Mobile Ads v 3.0.4 plugin and did not find anything unusual. 

I would suggest you to run against the latest version and use ARC as the latest plugin assumes that this is enabled by default. While profiling, you must know that persistent memory is what needs to kept eye on against transient ones. This is because the transient allocated memory would be flushed when needed by the device. So if the persistent memory is never decreased, even after a Banner View or Interstitial or any Ad View being removed, it means that there is an issue with memory deallocations. This is something that I did not find when I used the latest mentioned version to profile. The spikes in the persistent memory quickly declined when the AdView was either dismissed or removed. 

So if you still find irregularities on the latest version or need any further help with this, let us know!

Thanks,
Veer Busani
Mobile Ads SDK Team

profile.png

EdB

unread,
Jul 8, 2016, 8:05:14 PM7/8/16
to Google Mobile Ads SDK Developers
Hi there,

Is there a reason why you are not on the latest Unity build? It would not be valid to check with an older version how memory is being handled. I just did some profiling with the latest Unity 5.3.5f1 and Mobile Ads v 3.0.4 plugin and did not find anything unusual. 

I would suggest you to run against the latest version and use ARC as the latest plugin assumes that this is enabled by default. While profiling, you must know that persistent memory is what needs to kept eye on against transient ones. This is because the transient allocated memory would be flushed when needed by the device. So if the persistent memory is never decreased, even after a Banner View or Interstitial or any Ad View being removed, it means that there is an issue with memory deallocations. This is something that I did not find when I used the latest mentioned version to profile. The spikes in the persistent memory quickly declined when the AdView was either dismissed or removed.

I'd prefer to stay with using Unity 4.7 because the project has been thoroughly tested using that generation of Unity. 

"It would not be valid to check with an older version how memory is being handled"
- I guess I'll take that to mean that you're not going to bother with supporting Unity 4.x, although 3.0.5 fixed the Unity 4.x JSONUtility error...

Ok - thanks for the replies!  Good to get some answers.

Veer Arjun Busani(Mobile Ads SDK Team)

unread,
Jul 8, 2016, 9:44:55 PM7/8/16
to Google Mobile Ads SDK Developers
Hi there,

We certainly still support Unity 4+. The only issue here would be that Unity IDE itself is not in our control. We always encourage to test with the latest versions and migrate to them as soon as feasible. Having said that, I do not see any issue with the SDK itself and if you are using the latest SDK and not on the latest Unity IDE, an acceptable assumption would be to upgrade the Unity version itself. Also, I can tell you that the SDK for iOS natively is the same for Unity as the plugin only acts as an extension for the Unity library to be able to import the headers. The plugin also is open sourced as well. You can also test directly with our SDK in iOS as there must not be any difference otherwise. If you notice a difference between Unity versions, I'm inclined to think that this would certainly not be due to the SDK itself.

I understand that you may not be able to migrate to the latest versions and we still support Unity 4. One of the reasons we fixed the legacy issue. Memory issue on the other hand might make sense to be tested with the latest versions. Unity iOS build is written almost entirely in C++. All I'm asking is you to check with the latest version and let me know if you are still able to replicate the issue.

Thanks,
Veer Busani
Mobile Ads SDK Team

EdB

unread,
Jul 9, 2016, 7:02:05 PM7/9/16
to Google Mobile Ads SDK Developers
I made an attempt to upgrade to Unity 5.3.5 but there's too many other issues with my project so I need to stick with 4.7.2.

I'll make something work - thanks for you help!
Reply all
Reply to author
Forward
0 new messages