插页式广告每次以单位5显示时,内存会不断增加 [英] Memory goes on Increasing each time the interstitial ad is display in unity 5

查看:77
本文介绍了插页式广告每次以单位5显示时,内存会不断增加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用google admob在unity 5中显示插页式广告.我从github下载了googleads移动unity软件包和googlemobileadssdkios.我在Xcode中构建并运行游戏,该游戏显示横幅广告和插页式广告.我正在使用调试导航器来查看每次加载和关闭广告时的内存消耗.我注意到,每次插入插页式广告时,内存消耗都在增加.这意味着在关闭插页式广告时不会释放出内存.

I am using google admob for showing interstitial ads in unity 5. I download the googleads mobile unity package and googlemobileadssdkios from github. I build and run the game in Xcode it shows banner ads and interstitial ads. I am using debug navigator to view the memory consumption each time the ads is loaded and closed. I noticed that the memory consumption is increasing each time the interstitial ad is loaded. That means memory does not get free up while closing the interstitial ads.

我从github下载的源代码没有任何改变.如果内存以这种方式增加,则由于内存不足,应用程序将被终止.那么,在插页式广告关闭后如何释放内存?

I have change nothing in the source code downloaded from github. If memory goes increasing in this pattern, the application will be terminated due to insufficient memory. So, how to free up the memory after the interstitial ad is closed?

推荐答案

问题可能出在您使用InterstitialAd API的方式上.如果使用不正确,将会导致内存泄漏.

The problem is likely how you use the InterstitialAd API. You will get memory leak if not used correctly.

如果您要在函数内创建新的插页式实例,并且实例变量被声明为局部变量,则必须在函数结束之前或丢失对的引用之前调用插页式类的Destroy函数插页类.

If you are creating new interstitial instance inside a function and the instance variable is declared as a local variable, you have to call the Destroy function of the interstitial class before the end of the function or before you lose the reference to the interstitial class.

例如:

void showAdFunction()
{

    InterstitialAd interstitial = new InterstitialAd(adUnitId);
    AdRequest request = new AdRequest.Builder().Build();
    //.... 
    interstitial.LoadAd(request);
    interstitial.Destroy(); //Must do this before losing the reference
}

现在,如果您将InterstitialAd实例作为全局变量,并且内部脚本被另一个脚本破坏,则您还必须在OnDestroy函数中破坏InterstitialAd实例./p>

Now, If the you have the InterstitialAd instance as a global variable and the script it is inside is being destroyed by another script, you have to destroy the InterstitialAd instance as well in the OnDestroy function.

private InterstitialAd interstitial;

void showAdFunction()
{

    interstitial = new InterstitialAd(adUnitId);
    AdRequest request = new AdRequest.Builder().Build();
    //....   
    interstitial.LoadAd(request);
}

void OnDestroy()
{
    interstitial.Destroy(); //Destroy
}

这篇关于插页式广告每次以单位5显示时,内存会不断增加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆