<?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.0%2FDevelopers%2FTutorials%2FMemoryManagement</id>
	<title>Documentation/4.0/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.0%2FDevelopers%2FTutorials%2FMemoryManagement"/>
	<link rel="alternate" type="text/html" href="https://www.slicer.org/w/index.php?title=Documentation/4.0/Developers/Tutorials/MemoryManagement&amp;action=history"/>
	<updated>2026-04-04T00:03:42Z</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.0/Developers/Tutorials/MemoryManagement&amp;diff=32575&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.0/Developers/Tutorials/MemoryManagement&amp;diff=32575&amp;oldid=prev"/>
		<updated>2013-06-14T07:35:34Z</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:35, 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.0/Developers/Tutorials/MemoryManagement&amp;diff=25276&amp;oldid=prev</id>
		<title>Fedorov: Created page with 'From http://massmail.spl.harvard.edu/public-archives/slicer-devel/2011/007513.html  Like VTK, Slicer contains some &quot;factory&quot; methods:  - vtkMRMLScene::CreateNodeByClass()  - vtkM…'</title>
		<link rel="alternate" type="text/html" href="https://www.slicer.org/w/index.php?title=Documentation/4.0/Developers/Tutorials/MemoryManagement&amp;diff=25276&amp;oldid=prev"/>
		<updated>2012-04-02T14:28:35Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;#039;From http://massmail.spl.harvard.edu/public-archives/slicer-devel/2011/007513.html  Like VTK, Slicer contains some &amp;quot;factory&amp;quot; methods:  - vtkMRMLScene::CreateNodeByClass()  - vtkM…&amp;#039;&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>Fedorov</name></author>
		
	</entry>
</feed>