Find out how much memory is being used by an object

Asked by rod

Hello,

I'd like to know if there is any memory profiler (compatible with the current jython interpreter used by Sikuli) or similar tools in order to find out how much memory is being used by an instantiated object anytime during its life.

I've some memory consuming problems and I don't know how to free memory before it's too late ...

NB : I've a sikuli-1.0.1 installed on a Windows7 (X64) with JRE7

Thanks a lot,
Rod

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

Since we are finally running on Java, you can use any Java profiler (e.g. the features available in NetBeans, ...)

You might run your script from a Java app using (so you can use the Java profiler):

org.sikuli.basics.SikuliScript.main(args);

Revision history for this message
RaiMan (raimund-hocke) said :
#2

.... but what do you think are your memory problems?

The most consuming objects are the images and their in-memory representations down the line, but currently their are no known memory leaks with Sikuli.

Revision history for this message
rod (rodhiguain) said :
#3

I found that my "most consuming memory object" is a list containing some objects (no images or sikuli stuff ... but my own objects).
I tried to delete this list after having used it using :
del mylist[0:len(mylist)]

The problem is that mylist still stays in memory !!

How can I force the garbage collection in jython in order to really delete this list and free the memory ?
Is there any "gc" module so that i can import it and do something like gc.collect() ?

Thanks again

Revision history for this message
Best RaiMan (raimund-hocke) said :
#4

since we are in Jython context, you might use any Java features.
Besides del, there is no other possibility, to trigger GC in Jython.

del mylist[0:len(mylist)] should make a del to each element in myList. Elements, that then have a reference count of 0 are eligible for garbage collection (but with todays Java, you cannot really influence, when GC does its job).

So to make things eligible for garbage collection, you must be sure, that the ref count for an object is 0 (in your case this might not be depending how the list elements where created).

Revision history for this message
rod (rodhiguain) said :
#5

Thanks RaiMan, that solved my question.