Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak? #23

Closed
mike8699 opened this issue Mar 30, 2022 · 5 comments · Fixed by #24
Closed

Memory leak? #23

mike8699 opened this issue Mar 30, 2022 · 5 comments · Fixed by #24
Labels
DeSmuME-Core-Issue This seems to be a general issue in DeSmuME itself

Comments

@mike8699
Copy link
Contributor

mike8699 commented Mar 30, 2022

I'm using py-desmume to assist with automated testing on my project. I have a series of pytest-driven tests that use py-desmume to open various NDS roms in desmume, control them, inspect their memory contents, etc. I have a singleton instance of desmume.emulator.DeSmuME that I call .open(<rom_path>) on at the start of every test.

This has worked extremely well up to this point, when I had only a couple tests. However, now that the number of tests has grown significantly, I'm running into memory usage issues. Memory usage seems to continuously climb as more roms are opened, almost as if the emulator is not properly "closing" the currently running rom and freeing it from memory. I've collected some metrics below - each time entry represents a new call to DeSmuME.open().

    Time         Memory usage (%)
---------------  ----
23:03:58.733414  23.3
23:04:35.335415  28.8
23:05:13.583826  34.5
23:05:51.558359  40.9
23:06:29.880842  53.8
23:07:08.236224  66.1
23:07:09.310240  66.4
23:07:48.239835  78.3
23:08:27.003041  91.0
23:09:06.626569  94.7
23:09:47.978964  95.7

I did not see any DeSmuME.close() method in the API docs - is there a way to tell py-desmume to close the current ROM and free its memory without calling destroy() on the entire object? If not, I think there may be some sort of memory leaking going on.

@mike8699 mike8699 changed the title Memory leak Memory leak? Mar 30, 2022
mike8699 added a commit to phst-randomizer/ph-randomizer that referenced this issue Mar 30, 2022
This bug needs to be resolved upstream in py-desmume SkyTemple/py-desmume#23 to allow more test parameters
mike8699 added a commit to phst-randomizer/ph-randomizer that referenced this issue Mar 30, 2022
This bug needs to be resolved upstream in py-desmume SkyTemple/py-desmume#23 to allow more test parameters
mike8699 added a commit to phst-randomizer/ph-randomizer that referenced this issue Mar 30, 2022
This bug needs to be resolved upstream in py-desmume SkyTemple/py-desmume#23 to allow more test parameters
@theCapypara
Copy link
Member

Hi! I checked this upstream in the interface code and cross-checked it with the GUI for Windows and it seems that everything is done correctly? This seems to be a general memory leak issue in DeSmuME itself then? I will mark this issue was an upstream issue, you might want to consider checking if you can reproduce this with the GUI frontends & opening an issue about this at https://github.com/TASemulators/desmume.

@theCapypara theCapypara added the DeSmuME-Core-Issue This seems to be a general issue in DeSmuME itself label Mar 30, 2022
@theCapypara
Copy link
Member

Actually I found a function to free the currently loaded ROM, I will add this to the interface code & to py-desmume. Still seems to me like this leak is also present in the GUIs since it doesn't seem to be used when opening a new ROM.

@theCapypara
Copy link
Member

Opened a PR: TASEmulators/desmume#518

@mike8699
Copy link
Contributor Author

Thanks for the quick action on this! I'll see if I can reproduce this with the desmume GUI and report my findings in the upstream repo.

@mike8699
Copy link
Contributor Author

mike8699 commented Apr 3, 2022

Just to follow up on the specific use case I mentioned in the OP - since upgrading to the latest release (0.0.4.post1 as of this comment), I no longer encounter the memory leak when opening several consecutive roms. In fact, my test suite has 105 tests so far, each of which open a new rom in py-desmume, and the entire test suite runs to completion without any abnormal memory usage 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DeSmuME-Core-Issue This seems to be a general issue in DeSmuME itself
Projects
None yet
2 participants