How can I see that in the garbage collector

I am studying a security issue. One of these problems will ask me to retrieve data that has been destroyed and stored in memory until a garbage collector appears.

I've tried a lot. I want to know if it is possible to unload process memory from the python console.

In addition, the call gives us the python console, but instead of "β†’>" there is a stopwatch. How can they do something like this? I just have ssh access that runs the python console.

thanks

+5
source share
1 answer

You can use the code below to find out what's in the trash.

import gc def dump_garbage(): """ show us what the garbage about """ # force collection print("\nGARBAGE:") gc.collect() print("\nGARBAGE OBJECTS:") for x in gc.garbage: s = str(x) if len(s) > 80: s = s[:80] print(type(x),"\n ", s) if __name__=="__main__": import gc gc.enable() gc.set_debug(gc.DEBUG_LEAK) # make a leak l = [] l.append(l) del l # show the dirt ;-) dump_garbage() 
0
source

Source: https://habr.com/ru/post/1270960/


All Articles