In most examples on this site, various variables are being created.
For example, this script:
data=SeismicData('F:\\Data\\Segy\\Attributes\\cdp_stack.xgy')
creates a variable of type SeismicData with the name "data"
The Python interpreter will keep this variable in its scope until explicitly removed. INTViewer's memory will be affected until this variable is removed. Also, If many data variables are kept, this could also result in multiple file handles staying open. On Linux, there is a maximum number of file handles that are permitted. If this maximum is reached, users will encounter a "Too many open files" message.
To avoid this, be sure to delete any data variable that is no longer needed. The simplest way to do this is to set that variable to None (or an empty array).
Example:
data=SeismicData('F:\\Data\\Segy\\Attributes\\cdp_stack.xgy')
# do something with the data
data=None # removes this SeismicData instance from the scope
As the number of scripts in INTViewer grows, you can use the script below to check for left-over variables that were not removed. In this example, we check for variables with the type SeismicData. You can download this script at the bottom of this page.
simpleClassName = "SeismicData"
localsMap = locals()
isAnythingFound = False
for key in list(localsMap):
currentType = type(localsMap[key])
currentTypeName = currentType.__name__
if (currentTypeName == simpleClassName):
isAnythingFound = True
print 'Found variable \"' + key + '\" with type ' + simpleClassName
if (not isAnythingFound):
print 'No variable found with type ' + simpleClassName
See below how to force a garbage collection after setting a variable to None.
Just like the Java Virtual Machine, the Python interpreter garbage collects unreferenced objects automatically. The following script forces a garbage collection of a dataset in the Python interpreter:
import gc
seismicData = SeismicData('/home/myaccount/mydata.sgy')
seismicData = None
dataManager=DataManager()
dataManager.clearCache('/home/myaccount/mydata.sgy')
gc.collect()
Calling clearCache will work as intended only if the associated dataset is not visualized anywhere in INTViewer