<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.slicer.org/w/index.php?action=history&amp;feed=atom&amp;title=Documentation%2F4.1%2FDevelopers%2FTutorials%2FMemoryManagement</id>
	<title>Documentation/4.1/Developers/Tutorials/MemoryManagement - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.slicer.org/w/index.php?action=history&amp;feed=atom&amp;title=Documentation%2F4.1%2FDevelopers%2FTutorials%2FMemoryManagement"/>
	<link rel="alternate" type="text/html" href="https://www.slicer.org/w/index.php?title=Documentation/4.1/Developers/Tutorials/MemoryManagement&amp;action=history"/>
	<updated>2026-05-03T18:40:17Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.33.0</generator>
	<entry>
		<id>https://www.slicer.org/w/index.php?title=Documentation/4.1/Developers/Tutorials/MemoryManagement&amp;diff=32188&amp;oldid=prev</id>
		<title>UpdateBot: Prepend documentation/versioncheck template. See http://na-mic.org/Mantis/view.php?id=2887</title>
		<link rel="alternate" type="text/html" href="https://www.slicer.org/w/index.php?title=Documentation/4.1/Developers/Tutorials/MemoryManagement&amp;diff=32188&amp;oldid=prev"/>
		<updated>2013-06-14T07:21:23Z</updated>

		<summary type="html">&lt;p&gt;Prepend documentation/versioncheck template. See http://na-mic.org/Mantis/view.php?id=2887&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 07:21, 14 June 2013&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot; &gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;noinclude&amp;gt;{{documentation/versioncheck}}&amp;lt;/noinclude&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;From http://massmail.spl.harvard.edu/public-archives/slicer-devel/2011/007513.html&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;From http://massmail.spl.harvard.edu/public-archives/slicer-devel/2011/007513.html&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>UpdateBot</name></author>
		
	</entry>
	<entry>
		<id>https://www.slicer.org/w/index.php?title=Documentation/4.1/Developers/Tutorials/MemoryManagement&amp;diff=28435&amp;oldid=prev</id>
		<title>Finetjul at 14:57, 9 October 2012</title>
		<link rel="alternate" type="text/html" href="https://www.slicer.org/w/index.php?title=Documentation/4.1/Developers/Tutorials/MemoryManagement&amp;diff=28435&amp;oldid=prev"/>
		<updated>2012-10-09T14:57:40Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 14:57, 9 October 2012&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l17&quot; &gt;Line 17:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 17:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;manually in your code:&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;manually in your code:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;nodes = slicer.mrmlScene.GetNodesByClass('vtkMRMLLinearTransformNode')&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;nodes = slicer.mrmlScene.GetNodesByClass('vtkMRMLLinearTransformNode')&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;nodes.&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;SetReferenceCount&lt;/del&gt;(&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;1&lt;/del&gt;)      # ----&amp;gt; (was 2, keep 1 for the python&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;nodes.&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;UnRegister&lt;/ins&gt;(&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;slicer.mrmlScene&lt;/ins&gt;)      # ----&amp;gt; (&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;reference count &lt;/ins&gt;was 2, keep 1 for the python reference)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;reference)&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;...&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;...&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l43&quot; &gt;Line 43:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 42:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  n = slicer.mrmlScene.CreateNodeByClass('vtkMRMLViewNode')&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  n = slicer.mrmlScene.CreateNodeByClass('vtkMRMLViewNode')&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  slicer.mrmlScene.addNode(n)&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  slicer.mrmlScene.addNode(n)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  n.&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;SetReferenceCount&lt;/del&gt;(&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;n&lt;/del&gt;.&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;GetReferenceCount() - 1&lt;/del&gt;)&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  n.&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;UnRegister&lt;/ins&gt;(&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;slicer&lt;/ins&gt;.&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;mrmlScene&lt;/ins&gt;)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Even better, this specific example can be simplified using the following&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Even better, this specific example can be simplified using the following&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Finetjul</name></author>
		
	</entry>
	<entry>
		<id>https://www.slicer.org/w/index.php?title=Documentation/4.1/Developers/Tutorials/MemoryManagement&amp;diff=25589&amp;oldid=prev</id>
		<title>JChris.FillionR: 4.0 -&gt; 4.1</title>
		<link rel="alternate" type="text/html" href="https://www.slicer.org/w/index.php?title=Documentation/4.1/Developers/Tutorials/MemoryManagement&amp;diff=25589&amp;oldid=prev"/>
		<updated>2012-04-12T04:45:10Z</updated>

		<summary type="html">&lt;p&gt;4.0 -&amp;gt; 4.1&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;From http://massmail.spl.harvard.edu/public-archives/slicer-devel/2011/007513.html&lt;br /&gt;
&lt;br /&gt;
Like VTK, Slicer contains some &amp;quot;factory&amp;quot; methods:&lt;br /&gt;
 - vtkMRMLScene::CreateNodeByClass()&lt;br /&gt;
 - vtkMRMLScene::GetNodesByClass()&lt;br /&gt;
 - ...&lt;br /&gt;
Like in C++, it means that the functions return an object with a reference&lt;br /&gt;
count of 1 that nobody &amp;quot;owns&amp;quot; and the caller must take care of releasing&lt;br /&gt;
the object to avoid memory leak.&lt;br /&gt;
&lt;br /&gt;
While there is workaround for some methods (&lt;br /&gt;
slicer.mrmlScene.CreateNodeByClass('vtkMRMLModelNode') should be replaced&lt;br /&gt;
by slicer.vtkMRMLModelNode() ) there is currently no automatic/clean&lt;br /&gt;
mechanism to release the object created by such methods.&lt;br /&gt;
&lt;br /&gt;
The only &amp;quot;hack&amp;quot; that exists for now is to decrease the reference count&lt;br /&gt;
manually in your code:&lt;br /&gt;
nodes = slicer.mrmlScene.GetNodesByClass('vtkMRMLLinearTransformNode')&lt;br /&gt;
nodes.SetReferenceCount(1)      # ----&amp;gt; (was 2, keep 1 for the python&lt;br /&gt;
reference)&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
In C++, the following would apply:&lt;br /&gt;
vtkCollection* nodes =&lt;br /&gt;
mrmlScene-&amp;gt;GetNodesByClass(&amp;quot;vtkMRMLLinearTransformNode&amp;quot;);&lt;br /&gt;
...&lt;br /&gt;
nodes-&amp;gt;Delete();&lt;br /&gt;
&lt;br /&gt;
or using vtkSmartPointer:&lt;br /&gt;
vtkSmartPointer&amp;lt;vtkCollection&amp;gt; nodes;&lt;br /&gt;
nodes.TakeReference(mrmlScene-&amp;gt;GetNodesByClass(&amp;quot;vtkMRMLLinearTransformNode&amp;quot;));&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
Amendment from JC http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&amp;amp;revision=19772&lt;br /&gt;
&lt;br /&gt;
The reference count shouldn't be decreased using the naive approach where&lt;br /&gt;
it is set to one. Indeed, internally, the reference count could be any&lt;br /&gt;
number greater than one. It doesn't have to be 2.&lt;br /&gt;
&lt;br /&gt;
Considering this last remark, using the following approach is *REQUIRED*,&lt;br /&gt;
otherwise it will lead to a CRASH of the application.&lt;br /&gt;
&lt;br /&gt;
 n = slicer.mrmlScene.CreateNodeByClass('vtkMRMLViewNode')&lt;br /&gt;
 slicer.mrmlScene.addNode(n)&lt;br /&gt;
 n.SetReferenceCount(n.GetReferenceCount() - 1)&lt;br /&gt;
&lt;br /&gt;
Even better, this specific example can be simplified using the following&lt;br /&gt;
syntax, this is the *RECOMMENDED* approach, it will prevent bug, memory&lt;br /&gt;
leaks and crashes:&lt;br /&gt;
&lt;br /&gt;
  n = slicer.mrmlScene.addNode(slicer.vtkMRMLViewNode())&lt;br /&gt;
&lt;br /&gt;
And if the name of the node is generated at runtime, this could be done:&lt;br /&gt;
&lt;br /&gt;
  n = eval('slicer.mrmlScene.AddNode(slicer.%s())' % 'vtkMRMLViewNode')&lt;/div&gt;</summary>
		<author><name>JChris.FillionR</name></author>
		
	</entry>
</feed>