
CopyData causing a memory leak, am I doing something wrong?
Posted Thursday, 24 February, 2011 - 19:33 by Danny inI am having an issue with Monotouch and OpentTK. It appears from my testing that the CGDataProvider creates a memory leak when calling the CopyData method. If I am calling OnRenderFrame 30 times a second, the application runs out of memory. From other sites on objectiveC, I see the requirement for calling CGDataProviderRelease but I can not locate this.
For me this will become a major issue with my application on three views. Is there a workaround or am I missing something here.
Regards
Danny
=================================================
protected override void OnRenderFrame (FrameEventArgs e)
{
CreateValueImage ( p_Value, ;
}
private void CreateValueImage(float p_Value, UIFont p_TextFont,CGColor p_TextColor)
{
.
.
.
CGBitmapContext context = new CGBitmapContext(
System.IntPtr.Zero, // data
128, // width
64, // height
8, // bitsPerComponent
128*4, // bytesPerRow(NOTE: Use width since this is row)
_c , // colorSpace
CGImageAlphaInfo.PremultipliedLast)// bitmap
context.ShowTextAtPoint((128f - sizeOfString.Width)/2f,0f,_value);
using(CGImage image = context.ToImage()){
using(var provider = image.DataProvider){
using(NSData data = provider .CopyData()){
.
.
.
}
}
}
}


Comments
Re: CopyData causing a memory leak, am I doing something ...
Unfortunately, this appears like an issue in MonoTouch, which is closed-source, rather than OpenTK. Your best bet is to file a bug report with Novell.
As a workaround, you could DllImport CGDataProvideRelease manually. Something like this should work (untested, I don't have access to MonoTouch myself):
Where provider is a handle/Ref to the provider object.
Re: CopyData causing a memory leak, am I doing something ...
Thanks Fiddler,
We can always count on you to show us some path to follow. I will give this a try.
Again, thanks a bunch!!