Skip to content

Instantly share code, notes, and snippets.

@hinerm
Last active December 8, 2015 15:05
Show Gist options
  • Save hinerm/727453aab0837246367e to your computer and use it in GitHub Desktop.
Save hinerm/727453aab0837246367e to your computer and use it in GitHub Desktop.
Python memory leak
The following images show memory leaks due to mapped images not being cleaned up.
The MemoryOverview shows two hard reference paths keeping byte[] instances alive (blue and green). They both go through python classes to a HashMap.
The Objects1 and Objects2 images show these two paths expanded and reveals that we likely have two paths to the same map, and thus to the same set of objects.
Persumably our Python code is making these mappings but not cleaning up after them. Persumably there is also a hard reference to these images in ImageJ itself, so it would make sense on the Python side to cache WeakReferences to the images - or add some callback that ensures these mappings are eventually removed (or manually clean the maps at the end of the script).
To find the problematic python code we can look for the relevant variable names (snapshotPixels, rLUT1, bLUT1, gLUT1, etc...)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment