4

I have a MonoTouch app out in the wild that dies sometimes with mprotect errno 12 (out of memory), and it always seems to get at least one ReceiveMemoryWarning notification beforehand.

I'm wondering what the right way to respond to this is. There are two types of things that my app could free: OpenGL textures and managed memory.

My questions about this are:

  1. OpenGL textures: Will deleting OpenGL textures help?

  2. Managed memory: I can't free this directly, but I can get null out references to it. Is that enough?

  3. GC.Collect: Should I call GC.Collect() at the end of my handler? Does GC.Collect do anything immediately, or does it schedule a collection for the future?

  4. Anything else I can/should do in response to this?

Community
  • 1
  • 1
Mike
  • 1,169
  • 9
  • 26
  • Is it definitely not leaking? – vlad259 Apr 11 '11 at 15:16
  • To the best of my knowledge, it's not leaking. I'm tracking all OpenGL texture allocations and sound data (managed -- we have our own mixer), which are the largest bits of memory that we use. I've drastically reduced the amount of memory that these things use (we hover around 7MB texture memory and 2MB sound data), but it still dies sometimes due to lack of memory, especially after using either the .NET WebRequest APIs, the iOS image picker, or the MFMailComposer stuff. – Mike Apr 11 '11 at 15:43
  • 1
    Make sure you dispose your objects that you use in the WebRequest, as they could keep large buffers in memory for longer than you need them (ie, before the GC gets a chance to run) – miguel.de.icaza Apr 12 '11 at 21:51

1 Answers1

1

I ran into this a while back in my app using OpenGL. For me, it really was a memory leak.

[DllImport("/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics")] public static extern void CGDataProviderRelease(IntPtr provider);

and after you call GL.TexImage2D.....

you need to call CGDataProviderRelease(data.Handle);

now that being said, you might want to look at this:

http://forums.monotouch.net/yaf_postst1541.aspx

Danny
  • 31
  • 9
  • Thanks Danny. In your case, did the memory leak show up as such (or did you see memory usage growing) in Instruments? I'm not using CGDataProvider in my code anywhere (directly, at least) and I don't see my app's memory increasing in Instruments before it dies. – Mike Apr 12 '11 at 18:01
  • I've spent some time to isolate a case of this, and I've summarized the results in a [new question here](http://stackoverflow.com/questions/5666905/monotouch-instability-continues-managed-memory-allocator-crashes). – Mike Apr 14 '11 at 17:07