Is it good to use the new NSAutoReleasePool () in Monotouch as often as possible?

Wonder: to support MT, is this a good design / behavior for encapsulating code in NSAutoReleasePool() as often as possible? Or the same rules apply as for ObjC: create one if you loop a lot of data, create and delete many objects, or when creating new threads? When an area ends NSAutoReleasePool, will the MT free up memory immediately or will it be freed whenever it has time to do so?

+3
source share
1 answer

I created fairly large applications in MonoTouch that load a large amount of data (some of several megabytes several times), and I did not have to worry about NSAutoReleasePool at all. In general, the MonoTouch garbage collector works very well and handles most of the work for you.

Several times I run the method GC.Collect()myself, so I know that the data is immediately released, but this happens in very few cases.

It all depends on how you create your application. If only parts of the Apple structure are used for the user interface, you do not need to worry, as they will always be created / destroyed in the main user interface thread and are automatically assigned by NSAutoReleasePool. If you use other Apple frameworks in a separate thread, you need to have the object in place.

+2
source

All Articles