[MacRuby-devel] memory leaks

Laurent Sansonetti lsansonetti at apple.com
Tue Jul 6 14:08:25 PDT 2010


Hi Jakub,

Sorry for the late reply. I have been switching homes and was without internet access.

On Jun 30, 2010, at 2:22 PM, Jakub Suder wrote:

> Hi,
> 
> The users of my app are reporting to me that it takes way more memory
> than such app is supposed to. I've just released a new version that
> was supposed to improve this at least a bit, and someone commented
> that "I haven't even entered login and password and it already leaked
> almost a megabyte" (posting this screenshot from Instruments:
> http://static0.blip.pl/user_generated/update_pictures/1129697.jpg). I
> did a test - I've removed almost everything from the app except the
> login screen; and indeed, when started, the Leaks tool in Instruments
> shows about 800 KB of leaked memory (I suppose it goes up over time).
> All of that is shown as coming from libmacruby (though this really
> just means that the app is running MacRuby, as I understand).
> 
> Now, I'm wondering:
> - is this memory leaking because I'm doing something wrong (though
> there's not much things I could have done wrong in a login dialog...)
> - or is it leaking because MacRuby is doing something wrong
> - or is it not leaking at all really, and it's just that Instruments
> can't understand the memory managed by MacRuby and assumes it's leaked
> even if it's not?

Investigating memory leaks in a MacRuby app can be problematic because of the GC. (The same problem is also valid for pure Objective-C apps running in GC mode.) What you may see as leaks could potentially be false positives. Numbers reported by top(1) can also sometimes be wrong.

In general, memory leaks can easily be induced by the user, although it is unlikely here. There has been some work on eliminating memory leaks in the 0.6 release but there might still be some around.

What I would do:

1) build MacRuby trunk (just run rake macruby)
2) in the same directory, run your app like this (here, Foo): $ DYLD_LIBRARY_PATH=. MallocStackLogging=1 MallocStackLoggingNoCompact=1 /path/to/Foo.app/Contents/MacOS/Foo 
3) use your app a little bit, then when you're reading to measure leaks: $ leaks Foo > /tmp/Foo.leaks

Then, attach /tmp/Foo.leaks here.

> Here's a minimal version of the app:
> http://dl.dropbox.com/u/41808/macblip_mem_test.zip

How should I use it? It looks like it's asking me some kind of username/password.

Laurent


More information about the MacRuby-devel mailing list