poingstudios / godot-admob-plugin

This repository is for Godot's Addons to integrate natively AdMob to your Game Project without much configurations and directly inside Godot Editor!
https://poingstudios.github.io/godot-admob-plugin/
MIT License
334 stars 25 forks source link

Potential memory leak (?) #147

Open GenaTheCrocodile opened 4 months ago

GenaTheCrocodile commented 4 months ago

Godot version

4.2.2

Plugin version

3.1.1

Phone information

Huawei P40 lite JNY-LX1 EMUI version 12.0.0

Issue description

It seems like the admob plugin (on Android, can't test it on iOS) leaks memory. I tested it using the sample project that comes with the plugin. When you load and then free a rewarded ad, the object counter in godot doesn't decrease. Before loading any ads: image After loading and freeing rewarded ads: image

Steps to reproduce

  1. Create a new empty project and install the admob plugin
  2. Select Main.tscn (in addons/admob/sample) as the main scene
  3. Deploy with remote debug on android and open the objects' monitor
  4. Go to the rewarded tab on your phone (inside the sample app)
  5. Remember the current amount of objects
  6. Load and free an arbitrary amount of ads
  7. Check the number of objects

Additional context

No response

catabriga commented 4 months ago

I have noticed the same thing. After a stress test the application crashes due to memory usage only if the admob plugin is enabled.

Leotti commented 4 months ago

I found a memory leak in the AdView.gd script.

These RefCounted objects are never deleted because they connect the plugin's signals to lambda functions. The signals are never disconnected and so the references stay.

I'm not sure if this is the script responsible for the issue, but it could still cause some problems. I was able to fix the leak by using normal functions instead of anonymous lambdas. I added a cleanup function to disconnect all the signals, but it seems to work even without it. This might just be some of Godot's systems working that I don't understand.

gumaciel commented 4 months ago

Thank you for opening this issue, we will investigate

gumaciel commented 2 months ago

I can confirm this bug, but it's from other repository, I'll proceed with the migration