-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmemory_leak_demo_pls_help.py
44 lines (32 loc) · 1.17 KB
/
memory_leak_demo_pls_help.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from winrt.windows.media.control import GlobalSystemMediaTransportControlsSessionManager as MediaManager
from pympler.tracker import SummaryTracker
import asyncio
import gc
async def get_media_info():
# Memory leaking calls
sessions = await MediaManager.request_async()
current_session = sessions.get_current_session()
await current_session.try_get_media_properties_async()
# Force garbage collect, does nothing
gc.collect()
return
if __name__ == '__main__':
# Pause to check starting memory usage (I used task manager)
# ~ 30 MB in my case
input()
# Track objects and sizes
tracker = SummaryTracker()
# 500 iterations is a good example amount
for _ in range(500):
# Leak memory
asyncio.run(get_media_info())
# Force garbage collect, does nothing
gc.collect()
# Print info on object count and size differences
# Will always show ~ 1 MB of leaks, no matter how many iterations
tracker.print_diff()
# Pause to check ending memory usage (I used task manager)
# ~ 60 MB in my case with 500 iterations
# ~ 330 MB with 5000 iterations
# ~ 3.2 GB with 50000 iterations
input()