<?xml version="1.0" encoding="UTF-8"?>
	<rss version="2.0"
		xmlns:content="http://purl.org/rss/1.0/modules/content/"
		xmlns:wfw="http://wellformedweb.org/CommentAPI/"
		xmlns:dc="http://purl.org/dc/elements/1.1/"
		xmlns:atom="http://www.w3.org/2005/Atom"

			>

	<channel>
		<title>Cycling 74  &#187;  Topic: new JitterMatrix() leaking memory</title>
		<atom:link href="http://cycling74.com/forums/topic/new-jittermatrix-leaking-memory/feed" rel="self" type="application/rss+xml" />
		<link>http://cycling74.com/forums/topic/new-jittermatrix-leaking-memory/feed</link>
		<description></description>
		<pubDate>Wed, 19 Jun 2013 06:22:10 +0000</pubDate>
		<generator>http://bbpress.org/?v=2.2.4</generator>
		<language></language>

		
														
					
				<item>
					<guid>http://cycling74.com/forums/topic/new-jittermatrix-leaking-memory/#post-45644</guid>
					<title><![CDATA[new JitterMatrix() leaking memory]]></title>
					<link>http://cycling74.com/forums/topic/new-jittermatrix-leaking-memory/#post-45644</link>
					<pubDate>Mon, 28 Sep 2009 17:17:31 +0000</pubDate>
					<dc:creator>volker böhm</dc:creator>

					<description>
						<![CDATA[
						<p>hello,<br />
repeated use of new JitterMatrix() in an mxj external seems to cause max&#8217;s memory use to grow boundlessly.<br />
i don&#8217;t know much about garbage collection etc. but this doesn&#8217;t look right to me. <br />
if i start max and open e.g. one of the jitter-java examples that processes an incoming matrix (like javajitterfirsttest.maxpat or jitfeedback-example.maxpat), max uses something like 70 mb. after running this patch for an hour this value has grown to about 560 mb.</p>
<p>the problem seems to be with &#8220;new JitterMatrix()&#8221; as i see the same memory growth with the simple example code at the bottom.</p>
<p>intel mbp, osx 10.5.7, max 5.0.8</p>
<p><div class="pre"></div></p>
<pre>import com.cycling74.max.*;
import com.cycling74.jitter.*;

public class matrixTest extends MaxObject
 {
	public matrixTest()
	{
		declareIO(1, 1);
	}

	public void jit_matrix(String inname)
	{
		JitterMatrix mat = new JitterMatrix(inname);		

		outlet(0, "jit_matrix", inname);
	}
}</pre>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/new-jittermatrix-leaking-memory/#post-164637</guid>
					<title><![CDATA[Re: new JitterMatrix() leaking memory]]></title>
					<link>http://cycling74.com/forums/topic/new-jittermatrix-leaking-memory/#post-164637</link>
					<pubDate>Mon, 28 Sep 2009 20:12:14 +0000</pubDate>
					<dc:creator>Roth</dc:creator>

					<description>
						<![CDATA[
						<p>The memory leak is because you are creating a new JitterMatrix object every time you pass a matrix to your MXJ.  What you want to do is create your JitterMatrix object once in your constructor, and then just reassign it in your ji_matrix() method.  Something like this (although I can&#8217;t be sure this is exactly right as I don&#8217;t have any of my code that does this in front of me):</p>
<p>
<div class="pre"></div></p>
<pre>import com.cycling74.max.*;
import com.cycling74.jitter.*;

public class matrixTest extends MaxObject
{

	private JitterMatrix mat; //still works without private

	public matrixTest()
	{
		mat = new JitterMatrix();
		declareIO(1, 1);

	}

	public void jit_matrix(String inname)
	{
		mat.frommatrix(inname);		

		outlet(0, "jit_matrix", inname);
	}
}</pre>
<p>Untested, and it has been about six months since I&#8217;ve done this exactly, but something like that is what you need.</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/new-jittermatrix-leaking-memory/#post-164638</guid>
					<title><![CDATA[Re: new JitterMatrix() leaking memory]]></title>
					<link>http://cycling74.com/forums/topic/new-jittermatrix-leaking-memory/#post-164638</link>
					<pubDate>Mon, 28 Sep 2009 20:15:17 +0000</pubDate>
					<dc:creator>Roth</dc:creator>

					<description>
						<![CDATA[
						<p>Also, another thing about your code, you are actually not even using the internal matrix for your output.  I believe you are assigning the input to an internal matrix, and then outputting the input matrix name, not the internal matrix.  To output the internal matrix, you would want something like this.  Again, this is off the top of my head, so watch out!</p>
<p>
<div class="pre"></div></p>
<pre>import com.cycling74.max.*;
import com.cycling74.jitter.*;

public class matrixTest extends MaxObject
{

	private JitterMatrix mat; //still works without private

	public matrixTest()
	{
		mat = new JitterMatrix();
		declareIO(1, 1);

	}

	public void jit_matrix(String inname)
	{
		mat = frommatrix(inname);		

		outlet(0, "jit_matrix", mat.getName());
	}
}</pre>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/new-jittermatrix-leaking-memory/#post-164639</guid>
					<title><![CDATA[Re: new JitterMatrix() leaking memory]]></title>
					<link>http://cycling74.com/forums/topic/new-jittermatrix-leaking-memory/#post-164639</link>
					<pubDate>Mon, 28 Sep 2009 20:48:20 +0000</pubDate>
					<dc:creator>volker böhm</dc:creator>

					<description>
						<![CDATA[
						<p>
<table border="0" align="center" width="90%" cellpadding="3" cellspacing="1">
<tr>
<td class="SmallText"><b>Quote:</b></td>
</tr>
<tr>
<td class="quote">The memory leak is because you are creating a new JitterMatrix object every time you pass a matrix to your MXJ.</td>
</tr>
</table>
</p><p>yes, i&#8217;m aware of this. but i think it shouldn&#8217;t be like that.</p>
<p>
<table border="0" align="center" width="90%" cellpadding="3" cellspacing="1">
<tr>
<td class="SmallText"><b>Quote:</b></td>
</tr>
<tr>
<td class="quote">What you want to do is create your JitterMatrix object once in your constructor, and then just reassign it in your ji_matrix() method. </td>
</tr>
</table>
</p><p>the frommatrix method is what seems to work correctly &#8211; thanks for pointing me to it!<br />
and yes, forget about the outlet call. it isn&#8217;t even needed to demonstrate the problem.</p>
<p>i was simply modifying a source file from /examples/jitter-examples/java/. and they all use &#8220;new JitterMatrix()&#8221; inside the jit_matrix method. which obviously is a bad idea.<br />
someone should definitely correct these examples.</p>
<p>volker.</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/new-jittermatrix-leaking-memory/#post-164640</guid>
					<title><![CDATA[Re: new JitterMatrix() leaking memory]]></title>
					<link>http://cycling74.com/forums/topic/new-jittermatrix-leaking-memory/#post-164640</link>
					<pubDate>Mon, 28 Sep 2009 22:40:45 +0000</pubDate>
					<dc:creator>Roth</dc:creator>

					<description>
						<![CDATA[
						<p>
<table border="0" align="center" width="90%" cellpadding="3" cellspacing="1">
<tr>
<td class="SmallText"><b>volker b�hm wrote on Mon, 28 September 2009 16:48</b></td>
</tr>
<tr>
<td class="quote">
<table border="0" align="center" width="90%" cellpadding="3" cellspacing="1">
<tr>
<td class="SmallText"><b>Quote:</b></td>
</tr>
<tr>
<td class="quote">The memory leak is because you are creating a new JitterMatrix object every time you pass a matrix to your MXJ.</td>
</tr>
</table>
<p>yes, i&#8217;m aware of this. but i think it shouldn&#8217;t be like that.</p>
</td>
</tr>
</table>
</p><p>Makes sense on the Java end and I imagine some sort of fix to the Jitter Java library to avoid this could cause some other problems.</p>
<p>It would be really useful (if anyone with the power to make these changes is watching) to have this pointed out in the documentation, because I didn&#8217;t realize this myself until I noticed the memory leak.</p>
<table border="0" align="center" width="90%" cellpadding="3" cellspacing="1">
<tr>
<td class="SmallText"><b>volker b�hm wrote on Mon, 28 September 2009 16:48</b></td>
</tr>
<tr>
<td class="quote">
i was simply modifying a source file from /examples/jitter-examples/java/. and they all use &#8220;new JitterMatrix()&#8221; inside the jit_matrix method. which obviously is a bad idea.<br />
someone should definitely correct these examples.
</td>
</tr>
</table>
<p>
Yes! Not only should this be pointed out in the documentation, but those examples really should be fixed.  Hopefully that change can get made so others don&#8217;t have to find this thread to figure it out (or more likely, not realize the problem, but run into potentially HUGE memory leaks).</p>
<p>I guess I shouldn&#8217;t sit around hoping someone notices this thread.  I&#8217;ll send an email to support linking to this right now so hopefully this will be addressed.</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/new-jittermatrix-leaking-memory/#post-164641</guid>
					<title><![CDATA[Re: new JitterMatrix() leaking memory]]></title>
					<link>http://cycling74.com/forums/topic/new-jittermatrix-leaking-memory/#post-164641</link>
					<pubDate>Tue, 29 Sep 2009 00:00:36 +0000</pubDate>
					<dc:creator>Ben Bracken</dc:creator>

					<description>
						<![CDATA[
						<p>Yes, this looks to be a bug.  I&#8217;ll log it and we will look into it, but I am not not certain when it will be fixed. </p>
<p>The current workaround would be to do something like what Roth has suggested.</p>
<p>-Ben</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/new-jittermatrix-leaking-memory/#post-164642</guid>
					<title><![CDATA[Re: new JitterMatrix() leaking memory]]></title>
					<link>http://cycling74.com/forums/topic/new-jittermatrix-leaking-memory/#post-164642</link>
					<pubDate>Tue, 29 Sep 2009 00:21:55 +0000</pubDate>
					<dc:creator>Roth</dc:creator>

					<description>
						<![CDATA[
						<p>
<table border="0" align="center" width="90%" cellpadding="3" cellspacing="1">
<tr>
<td class="SmallText"><b><a href="mailto:ben@cycling74.com">ben@cycling74.com</a> wrote on Mon, 28 September 2009 20:00</b></td>
</tr>
<tr>
<td class="quote">Yes, this looks to be a bug.  I&#8217;ll log it and we will look into it, but I am not not certain when it will be fixed. </td></tr></table></p>
<p>The current workaround would be to do something like what Roth has suggested.</p>
<p>-Ben</p>



<p>I did a little searching and found this post from 3 years ago that I now remember looking at this spring when I ran into this problem.</p>
<p><a href="http://www.cycling74.com/forums/index.php?t=msg&#038;goto=75336&#038;rid=4220&#038;S=d002c59b26a677b6db151281208c7d44&#038;srch=garbage#msg_75336">http://www.cycling74.com/forums/index.php?t=msg&#038;goto=75336&#038;rid=4220&#038;S=d002c59b26a677b6db151281208c7d44&#038;srch=garbage#msg_75336</a></p>
<p>This lead me to believe that this was not a bug, but related to creating Java references to Max C objects causing the reference count to never fall to zero.  I don&#8217;t claim to be an expert Java programmer, but it seems to me that if the current Max/Java garbage collection issues were documented, it would actually be a feature.  Forcing the work around I mentioned would offer some CPU benefit as would not be allocating/deallocating objects at every method call.  It may not be much, but as someone who runs into many CPU walls, I&#8217;ll do everything I can. I realize fixing this &#8220;bug&#8221; would not prevent me from continuing to use my workaround, but it seems like a built in way of forcing more efficient style (at least if it were properly documented).</p>
<p>Thoughts?</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/new-jittermatrix-leaking-memory/#post-164643</guid>
					<title><![CDATA[Re: new JitterMatrix() leaking memory]]></title>
					<link>http://cycling74.com/forums/topic/new-jittermatrix-leaking-memory/#post-164643</link>
					<pubDate>Tue, 29 Sep 2009 15:54:45 +0000</pubDate>
					<dc:creator>Ben Bracken</dc:creator>

					<description>
						<![CDATA[
						<p>In talking with JKC, this sounds about right.  From the linked forum thread, JKC mentions:</p>
<p>&#8220;You will want to call JitterMatrix.freepeer() to free any C resources which are not handled fast enough by the garbage collector.&#8221;</p>
<p>It might be that the GC is not getting triggered on these objects aggressively (since it has no idea about the C memory behind the scenes).</p>
<p>So, in regards to the examples, it may be a case of &#8220;do as we say, not as we do&#8221; <img src="images/smiley_icons/icon_smile.gif" border=0 alt="Smile"/></p>
<p>-Ben</p>
						]]>
					</description>

					
					
				</item>

					
		
	</channel>
	</rss>

