firelab / viirs_ba

Python code for burned area estimation using VIIRS scenes.
Creative Commons Zero v1.0 Universal
7 stars 4 forks source link

Manual variable deletion #6

Closed bnordgren closed 8 years ago

bnordgren commented 8 years ago

I noticed a few patterns like this:

# Clean up arrays
Con = None
Lat = None
Lon = None
del Con
del Lat
del Lon

When doing this inside a function, this doesn't actually release any memory. The local variable Con no longer references whatever object was passed in, but whomever called the function is still holding a reference to it, so the object can't be freed. Removing Con from the local namespace (del Con) manually might be a little overzealous, particularly if the variable falls out of scope in the next few lines. :)

Are you doing this for a reason, or is this a holdover from programming languages which require manual memory management?

calbury commented 8 years ago

Bryce, I was having trouble with memory errors within the function execution and adding these deletions fixed it. I may have gotten a little overzealous with nulling and then deleting everything. I was a little frustrated at the time. If you want I could go back and experiment with how necessary they are..

[Forest Service Shield]

Carl Albury Remote Sensing Specialist

Forest Service Contractor Remote Sensing Applications Center

p: 801-975-3351 calbury@fs.fed.usmailto:calbury@fs.fed.us

2222 West 2300 South Salt Lake City, UT 84119 www.fs.fed.ushttp://www.fs.fed.us/ [USDA Logo]http://usda.gov/ [Forest Service Twitter] https://twitter.com/forestservice [USDA Facebook] https://www.facebook.com/pages/US-Forest-Service/1431984283714112

Caring for the land and serving people

From: bnordgren [mailto:notifications@github.com] Sent: Tuesday, February 16, 2016 8:58 PM To: firelab/viirs_ba viirs_ba@noreply.github.com Subject: [viirs_ba] Manual variable deletion (#6)

I noticed a few patterns like this:

Clean up arrays

Con = None

Lat = None

Lon = None

del Con

del Lat

del Lon

When doing this inside a function, this doesn't actually release any memory. The local variable Con no longer references whatever object was passed in, but whomever called the function is still holding a reference to it, so the object can't be freed. Removing Con from the local namespace (del Con) manually might be a little overzealous, particularly if the variable falls out of scope in the next few lines. :)

Are you doing this for a reason, or is this a holdover from programming languages which require manual memory management?

— Reply to this email directly or view it on GitHubhttps://github.com/firelab/viirs_ba/issues/6.

This electronic message contains information generated by the USDA solely for the intended recipients. Any unauthorized interception of this message or the use or disclosure of the information it contains may violate the law and subject the violator to civil or criminal penalties. If you believe you have received this message in error, please notify the sender and delete the email immediately.

bnordgren commented 8 years ago

All good, just wondering.