Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by MaxUnity111 · Mar 09, 2020 at 10:48 AM · admobmemory-leak

Memory leak

Greetings, I have a script for displaying rewarding ads that hangs on the prefab button. This button is located on two different panels in each stage. On the Android device, only the end of the advertisement starts to appear after ten scenes and the player is not rewarded, and after twenty scenes the game is interrupted, therefore that there is a memory leak.link text

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using GoogleMobileAds.Api;
 using UnityEngine.Monetization;
 using System;
 
 public class MineBtn : MonoBehaviour
 {
     public int valueOfButton = 5;
     public bool admob = true;
     private FieldFillingManager ffm;
     private double amount = 0;
     private int countUpdate = 0;
 
 # if UNITY_ANDROID
     private const string ad_reward_diamonds = "ca-app-pub-9578413026007667/3802113406";
     private const string ad_reward_filedPanel = "ca-app-pub-9578413026007667/8330371577";
     private const string test_adID = "ca-app-pub-3940256099942544/5224354917";
     private string admob_ID;
     private RewardedAd rewardedAdDiamonds;
     private RewardedAd rewardedAdFiled;
 
 #endif
 
     // Use this for initialization
     void Start()
     {       
         GetComponentInChildren<Text>().text = "+" + valueOfButton.ToString();
         ffm = FindObjectOfType<FieldFillingManager>();
 #if UNITY_ANDROID       
 
         if (admob)
         {
 //            MobileAds.Initialize("ca-app-pub-9578413026007667~1116240310");  перенес в FieldFillingManager
             if (GetComponentInParent<FailedPanel>())
             {
                 admob_ID = ad_reward_filedPanel;
                 this.rewardedAdFiled = CreateAndLoadRewardedAd(test_adID);//ad_reward_filedPanel);
             }
             else
             {
                 admob_ID = ad_reward_diamonds;
                 this.rewardedAdDiamonds = CreateAndLoadRewardedAd(test_adID);// ad_reward_diamonds);
             }
             //           admob_ID = test_adID;
         }
 #endif
     }
 
     public RewardedAd CreateAndLoadRewardedAd(string adUnitId)
     {
         RewardedAd rewardedAd = new RewardedAd(adUnitId);
 
         rewardedAd.OnAdLoaded += HandleRewardedAdLoaded;
         rewardedAd.OnAdFailedToLoad += HandleRewardedAdFailedToLoad;
         rewardedAd.OnAdOpening += HandleRewardedAdOpening;
         rewardedAd.OnAdFailedToShow += HandleRewardedAdFailedToShow;
         rewardedAd.OnUserEarnedReward += HandleUserEarnedReward;
         rewardedAd.OnAdClosed += HandleRewardedAdClosed;
 
         
        // AdRequest request = new AdRequest.Builder().AddTestDevice(AdRequest.TestDeviceSimulator).AddTestDevice("E2940A62C1B655BA").Build();
        // AdRequest request = new AdRequest.Builder().AddTestDevice("E2940A62C1B655BA").Build();
        AdRequest request = new AdRequest.Builder().Build();
 
         
         rewardedAd.LoadAd(request);   
         return rewardedAd;
     }
 
     public void ButtonClick()
     {
         
 #if UNITY_ANDROID
         
         if (admob)
         {
             if (GetComponentInParent<FailedPanel>())
             {
                 if (rewardedAdFiled.IsLoaded())
                 {
                     rewardedAdFiled.Show();
                 }
             }
             else
             {
                 if (rewardedAdDiamonds.IsLoaded())
                 {
                     rewardedAdDiamonds.Show();
                 }
             }
         }
 
 #endif
     }
 #if UNITY_ANDROID
 
 
     public void HandleRewardedAdLoaded(object sender, EventArgs args)
     {
         Debug.Log("HandleRewardedAdLoaded event received ");
         
     }
 
     public void HandleRewardedAdFailedToLoad(object sender, AdErrorEventArgs args)
     {
         Debug.Log("HandleRewardedAdFailedToLoad event received with message: " + args.Message);        
     }
 
     public void HandleRewardedAdOpening(object sender, EventArgs args)
     {
         Debug.Log("HandleRewardedAdOpening event received ");        
 
     }
 
     public void HandleRewardedAdFailedToShow(object sender, AdErrorEventArgs args)
     {     
         Debug.Log("HandleRewardedAdFailedToShow event received with message: "
                              + args.Message);
     }
 
     public void HandleRewardedAdClosed(object sender, EventArgs args)
     {        
            Debug.Log("HandleRewardedAdClosed");
     }
 
     public void HandleUserEarnedReward(object sender, Reward args)
     {
         string type = args.Type;
         amount = args.Amount;
         ffm.SetDiamonds(ffm.GetDiamonds() + (int)amount);
         Debug.Log("UserEarnedReward");
     }
 
 #endif
 }

minebtn.txt (4.3 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

201 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

assetBundle memory can not be free 0 Answers

Memory error pls help 0 Answers

Help with AdMob interstitials 0 Answers

"Module 'GoogleMobileAds' not found." 1 Answer

Admob impressions are not counted 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges