存储器的推移每次插播式广告是显示增加团结5(Memory goes on Increasing ea

2019-09-26 08:31发布

我使用谷歌的AdMob展示团结5.我下载googleads移动统一包装和googlemobileadssdkios从GitHub插页广告。 我建立并运行游戏在Xcode它显示横幅广告和插页广告。 我使用调试导航每个广告加载和关闭时间,查看内存的消耗。 我注意到,内存消耗为每个插页式广告加载时间的增加。 这意味着内存没有得到释放,同时关闭插页式广告。

我改变什么在从GitHub下载源代码。 如果内存在那张这种模式的增加,应用程序将被终止由于内存不足。 因此,插页式广告关闭后,如何释放内存?

Answer 1:

你如何使用的问题很可能InterstitialAd API。 你会得到内存泄漏如果使用不正确。

如果您在函数内部创建新实例间质和实例变量声明为局部变量,你必须调用Destroy函数结束前的间隙类的功能,或者你失去了参考间质性上课前。

例如:

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实例作为全局变量和脚本它内部将被另一个脚本破坏,你必须销毁InterstitialAd实例以及在OnDestroy功能。

private InterstitialAd interstitial;

void showAdFunction()
{

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

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


文章来源: Memory goes on Increasing each time the interstitial ad is display in unity 5
标签: c# xcode unity3d