Ticket #4305 (closed: wontfix)

Opened 9 years ago

Last modified 5 years ago

Python: ws.getInstrument holds onto memory

Reported by: Martyn Gigg Owned by: Martyn Gigg
Priority: critical Milestone: Release 2.3
Component: Mantid Keywords:
Cc: Blocked By:
Blocking: Tester: Russell Taylor

Description (last modified by Martyn Gigg) (diff)

Run the script below and then open up a process monitor. On windows it is using ~ 450Mb, click the 'Clear all memory' option and the usage doesn't change.

idf_file = 'LET_Definition.xml'
ws = LoadEmptyInstrument(idf_file)
instr = ws.getInstrument()

Change History

comment:1 Changed 9 years ago by Martyn Gigg

  • type changed from enhancement to defect

comment:2 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:3 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:4 Changed 8 years ago by Martyn Gigg

  • Description modified (diff)

comment:5 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:6 Changed 8 years ago by Martyn Gigg

  • Description modified (diff)

comment:7 Changed 8 years ago by Martyn Gigg

  • Status changed from new to accepted

comment:8 Changed 8 years ago by Martyn Gigg

  • Status changed from accepted to verify
  • Resolution set to wontfix

So this is down to the fact that the getInstrument call returns a shared pointer so Python holds on to the memory. If you add a line instr = None at the end to drop it & then click clear the memory will be freed.

In this case we have to return a shared pointer because the getInstrument call creates a new parametrized instrument object so it needs to be kept alive by something. The real "problem" is that the parameterized instrument stores a shared pointer, if it stored a weak pointer then this wouldn't be a problem. However this would slow access to the base instrument pointer as each call to the weak one would have to check whether the other was still alive and temporarily promote it to a shared pointer, creating a lot of additional work.

comment:9 Changed 8 years ago by Russell Taylor

  • Status changed from verify to verifying
  • Tester set to Russell Taylor

comment:10 Changed 8 years ago by Russell Taylor

  • Status changed from verifying to closed

Agreed.

comment:11 Changed 5 years ago by Stuart Campbell

This ticket has been transferred to github issue 5152

Note: See TracTickets for help on using tickets.