Search Unity

Memory problem Unity Ads on Android

Discussion in 'Unity Ads & User Acquisition' started by Victor_Kallai, Nov 27, 2014.

  1. Victor_Kallai

    Victor_Kallai

    Joined:
    Mar 5, 2014
    Posts:
    123
    Memory problem Unity Ads on Android
    Each time I call Advertisement.Show(null, showOptions); total memory increases by 20Mb and eventually the app freezes or restarts. I've tested this on HTC and Samsung S3. What am I doing wrong?

    Here is my code:
    Code (CSharp):
    1. public void ShowAds(Action onFinished = null, Action onSkipped = null, Action onFailed = null, Action onComplete = null)
    2.     {
    3.         if (Advertisement.isReady())
    4.         {
    5.             UserInterface.Instance.setTouchInput(false);
    6.             Advertisement.Show(null, new ShowOptions
    7.             {
    8.                 pause = true,
    9.                 resultCallback = delegate(ShowResult result)
    10.                 {
    11.                     Debug.Log("Unity Ads : " + result.ToString());
    12.  
    13.                     switch (result)
    14.                     {
    15.                         case ShowResult.Finished:
    16.                             if (onFinished != null)
    17.                                 onFinished();
    18.                             break;
    19.                         case ShowResult.Skipped:
    20.                             if (onSkipped != null)
    21.                                 onSkipped();
    22.                             break;
    23.                         case ShowResult.Failed:
    24.                             if (onFailed != null)
    25.                                 onFailed();
    26.                             break;
    27.                         default:
    28.                             throw new ArgumentOutOfRangeException("result");
    29.                     }
    30.  
    31.                     UserInterface.Instance.setTouchInput(true);
    32.  
    33.                     if (onComplete != null)
    34.                         onComplete();
    35.                 }
    36.             });
    37.         }
    38.     }
     
  2. Salazar

    Salazar

    Joined:
    Sep 2, 2013
    Posts:
    235
    Hello, Victor_Kallai,

    I couldnt see a mistake on your code, before your production code , did you try using unity-ads with some plain(simple)(basic) code for test purposes. Something default code just for test. Because with this code I cant see through whats going on with your (Action Type) .
    Also you can get better help from this forum with a logcat attachment.

    Thank you,
     
  3. Victor_Kallai

    Victor_Kallai

    Joined:
    Mar 5, 2014
    Posts:
    123
    There is nothing interesting in my Android log, I've already checked it; when the memory increases over a value, my game process is killed by Android os.
    I've checked with Unity profiler, each time I show an unity ad, the total memory increases with 20Mb but only on Android, this does not happen in Editor.
    Inside my game I call the above function like this:
    Code (CSharp):
    1.         UnityAdsManager.Instance.ShowAds(
    2.             delegate
    3.             {
    4.                 continueLevelFromFail();
    5.             }
    6.         );
    7.  
    I seems like the video ad object is left behind in memory, do I have to delete it myself? Shouldn't it be deleted automatically when I close the ad?