Reputation: 3074
I'm new to mono/iPhone and I'm developing an application that views a PDF document using an UIView for each page, placed in a UIScrollView. Every time I scroll to the next page, only the new page +/- 1 is retained in memory, the rest are flushed (not the UIViews, but the PDF pages).
However, when debugging on the device, after flipping through enough pages the app crash, and I can see in the application output that I have received memory warnings.
I assume this has to do with the bitmaps rendered on the UIViews not being purged from memory, so after some research I found the CGContextRelease() method in Objective C -- however, this doesn't exist in MonoTouch. The only similar method I could find was in the UIGraphics class, but that only deals with the "current" graphics context, whatever that is (I can't set it to an existing one, that's for sure).
So, how do I release the graphics context in a UIView? Is this possible at all? What are my options? Hope anyone can help, this is turning me insane..
Upvotes: 2
Views: 392
Reputation: 43553
CGContextRelease
is called automatically when the CGContext
instance is freed, either manually (when Dispose
is called) or when the Garbage Collector (GC) runs the finalizer.
If you are creating your own CGContext
instances you should call Dispose (or use using
) to ensure you control when the resources will be released. Otherwise the GC could take too long before collecting them, leading to an out-of-memory condition.
The same advice holds for any IDisposable
instance you create in your application (i.e. your problem could be related to something else).
Note: are you re-using your UIView ? or removing/disposing them ? (that's a likely candidate too)
Upvotes: 3