Ticket #3407 (closed: fixed)

Opened 9 years ago

Last modified 5 years ago

Memory Leak: when python algorithms fail

Reported by: Nick Draper Owned by: Martyn Gigg
Priority: critical Milestone: Release 2.5
Component: Mantid Keywords:
Cc: Blocked By:
Blocking: Tester: Peter Peterson

Description (last modified by Martyn Gigg) (diff)

If a python algorithm fails it appears that it is held in memory together with any shared pointer it holds.

Test case:

from MantidFramework import *
from mantidsimple import *

class SimplePowderDiffraction2(PythonAlgorithm):
    def category(self):
        return "Examples"

    def name(self):
        return "SimplePowderDiffraction"
    def version(self):
        return 2

    def PyInit(self):
        # Input file
        self.declareFileProperty("Filename", "", FileAction.Load)
	#cal file
        self.declareFileProperty("CalFile", "", FileAction.Load)
        # Output workspace to put the transmission histo into
        self.declareWorkspaceProperty("OutputWorkspace", "", Direction.Output)
        
    def PyExec(self):
        file = self.getProperty("Filename")
        calFile = self.getProperty("CalFile")
        
	tempWorkspace = "__tmp_SimplePowderDiffraction"
        
	#Load and Load RAW do now work with executeSubAlgorithms
	Load(file,tempWorkspace)
        tmpWs = mtd[tempWorkspace]
	
	a = self.executeSubAlg(AlignDetectors, tmpWs, tmpWs, CalibrationFile=calFile)
	tmpWs = a._getWorkspaceProperty("OutputWorkspace")
	mtd.sendLogMessage(str(type(tmpWs)))
	mtd.sendLogMessage(Error)
	a = self.executeSubAlg(DiffractionFocussing, tmpWs,"b", GroupingFileName=calFile)
	wspace = a._getWorkspaceProperty("OutputWorkspace")

        self.setProperty("OutputWorkspace", wspace)
	
	#need to delete the temp workspace names
	mtd.deleteWorkspace(tempWorkspace)
        
#############################################################################################

mtd.registerPyAlgorithm(SimplePowderDiffraction2())

Change History

comment:1 Changed 9 years ago by Martyn Gigg

  • Status changed from new to verify
  • Resolution set to fixed

In [13962]:

Fixes #3407. Ensure that the ref counts of the traceback, exception and value objects are decremented properly when a Python exception is translated into a C++ one. The traceback holds references to the local variables that were present when the exception was raised so it needs to be cleaned up for these objects to have their destructors called.

comment:2 Changed 9 years ago by Martyn Gigg

Note to tester: When the error is raised it will look as if there are no workspaces present but in fact the workspace used is hidden with this name '__tmp_SimplePowderDiffraction'. After the bugfix the memory should be freed when DeleteWorkspace('__tmp_SimplePowderDiffraction') is called. Before the bugfix calling delete had no effect.

comment:3 Changed 9 years ago by Janik Zikovsky

  • Status changed from verify to verifying
  • Tester set to Janik Zikovsky

comment:4 Changed 9 years ago by Janik Zikovsky

  • Status changed from verifying to verify
  • Tester Janik Zikovsky deleted

comment:5 Changed 9 years ago by Nick Draper

  • Status changed from verify to verifying
  • Tester set to Nick Draper

comment:6 Changed 9 years ago by Nick Draper

  • Priority changed from major to critical
  • Status changed from verifying to reopened
  • Resolution fixed deleted
  • Milestone changed from Iteration 30 to Iteration 31

still leaks on the first run, subsequent runs do not leak.

Error in execution of algorithm SimplePowderDiffraction:
Python error: global name 'Error' is not defined
  at line 33 in '<input>'

reopen to next iteration

comment:7 Changed 9 years ago by Nick Draper

testing was on windows 7

comment:8 Changed 9 years ago by Nick Draper

  • Milestone changed from Iteration 32 to Iteration 33

Moved to iteration 33 at iteration 32 code freeze

comment:9 Changed 8 years ago by Nick Draper

  • Milestone changed from Release 2.1 to Release 2.2

Moved at end of release 2.1

comment:10 Changed 8 years ago by Nick Draper

  • Milestone changed from Release 2.2 to Release 2.3

Moved at the end of release 2.2

comment:11 Changed 8 years ago by Martyn Gigg

  • Milestone changed from Release 2.3 to Release 2.4

comment:12 Changed 8 years ago by Martyn Gigg

  • Milestone changed from Release 2.4 to Release 2.5

comment:13 Changed 8 years ago by Martyn Gigg

  • Status changed from reopened to accepted

comment:14 Changed 8 years ago by Martyn Gigg

  • Status changed from accepted to verify
  • Resolution set to fixed
  • Description modified (diff)

Tested this again after fixing #6779 and it seems like the leak as gone away.

Tester: Take note of comment 2 and use the algorithm in the main description to test.

The algorithm loads a workspace into a hidden workspace name and then an error occurs. The workspace is still in memory and clicking 'File->Clear All Memory' should now remove the workspace from memory properly.

comment:15 Changed 8 years ago by Peter Peterson

  • Status changed from verify to verifying
  • Tester changed from Nick Draper to Peter Peterson

comment:16 Changed 8 years ago by Peter Peterson

  • Status changed from verifying to closed

This defect no longer exists. Very likely due to #6779 which have been on master for the better part of a week.

comment:17 Changed 5 years ago by Stuart Campbell

This ticket has been transferred to github issue 4254

Note: See TracTickets for help on using tickets.