-
-
Notifications
You must be signed in to change notification settings - Fork 667
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
Unlimited memory usage when calling several Image
and Region
methods from Python
#2705
Comments
This sounds like some |
Something else noteworthy... Replacing the content of the for loop with:
Fixes the memory issues... |
I am curious if the automatic conversion of a set "(a,b)" to an itk.Index is leaking memory. |
The odd thing is, both approaches give the same |
Updating the title and changing the description quite a bit, as this seems to be a family of issues. |
ImageRegion::IsInside
uncapped memory usageImage
and Region
methods from Python
How big is the memory leak? This might be related? Here is some information on how Python handles immutable objects like integers maybe some tuples? Try changing it from a tuple to a list? from an int to a float? |
I was wonding the same thing Brad!
I am curious if
https://stackoverflow.com/questions/1316767/how-can-i-explicitly-free-memory-in-python
An explicit garbage collection call would make valgrind happy. It seems like a corner case where the perceived memory leak is an artifact of optimizing the memory management for performance reasons.
Hans
From: Bradley Lowekamp ***@***.***>
Date: Thursday, August 26, 2021 at 7:25 AM
To: InsightSoftwareConsortium/ITK ***@***.***>
Cc: Hans Johnson ***@***.***>, Comment ***@***.***>
Subject: Re: [InsightSoftwareConsortium/ITK] Unlimited memory usage when calling several `Image` and `Region` methods from Python (#2705)
How big is the memory leak? This might be related?
Here is some information on how Python handles immutable objects like integers maybe some tuples?
https://freecontent.manning.com/mutable-and-immutable-objects/
Try changing it from a tuple to a list? from an int to a float?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<#2705 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AACMU4RF6U5COSGHXRCPVG3T6YXCZANCNFSM5C2ARVDA>.
Triage notifications on the go with GitHub Mobile for iOS<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android<https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email>.
|
Hi All, Its tough to tell how big the memory leak is, as using a tuple (which causes the issue) and using Changing from a tuple to a list still causes the same issue. Explicitly calling Let me know if there are other questions that I can answer, thanks. |
FYI - we think it's due to the use of Note, this memory issue should impact any method that is using the PyBase.i sequence/vec wrapper code. Our hypothesis is that the Python reuse of small integers and tuples was suppressing the memory leak. For me, after calling |
Fixes InsightSoftwareConsortium#2705. Calls to PySequence_GetItem have been updated in pyBase.i to decrement the reference count correctly.
Fixes InsightSoftwareConsortium#2705. Calls to PySequence_GetItem have been updated in pyBase.i to decrement the reference count correctly.
Description
The below Python programs seem to require unlimited memory.
Steps to Reproduce
This is a family of seemingly related issues, which have roughly the same setup. Run the below code to set up a few examples
With the above setup, run one of the following code cells and monitor memory usage. They all consume an unlimited amount of memory:
1.)
Region::IsInside
with tuple argument with x or y >= 256 or <= -62.)
Image::TransformPhysicalPointToIndex
with tuple argument with x or y >= 256 or <= -63.)
Image::TransformPhysicalPointToIndex
withitk.Point
argument with ANY value of x or y (as far as I can tell)4.)
Image::TransformIndexToPhysicalPoint
with tuple argument with x or y >= 256 or <= -6Swapping tuples for
itk.Index
arguments for cases 1 and 4 resolves the issue. From this source:"Python preallocates small integers in a range of -5 to 256. This allocation happens during initialization and since we cannot update integers (immutability) these preallocated integers are singletons and are directly referenced instead of reallocating. This means every time we use/creates a small integer, python instead of reallocating just returns the reference of preallocated one.". Thanks @brad-t-moore
This gives a hint to the above behavior.
Expected behavior
Actual behavior
Reproducibility
Versions
ITK 5.2.0
Environment
Python 3.6.9, Ubuntu 18.04
Additional Information
Valgrind output for case 1:
Valgrind gives the same summary when swapping a tuple out for an
itk.Index
argument in case 1The text was updated successfully, but these errors were encountered: