Ok thanks, main is our own class or series of classes or a class that may do other work etc. I'm thinking that make, use, dispose should be the best case making releasing of memory more important over GC.
-----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Jonathan Pryor Sent: Thursday, August 04, 2011 2:14 PM To: Discussions related to Mono for Android Subject: Re: [mono-android] question On Aug 4, 2011, at 2:01 PM, Tim Kelly wrote: > Now these are Service loops that never end while the program is running. Secnario#1 makes a new instance on each loop but would release resources (I'm assuming) and cause garbage collection. The first question: Is Class_Master_Main a Java.Lang.Object subclass? All Java.Lang.Object subclasses have two instances, one in the Dalvik VM and one in Mono's VM. As such, if you "know" that you won't be using an instance anymore, for optimal performance you should dispose of the managed instance, e.g. for Scenario #1: while (true) { using (var main = new Class_Master_Main ()) { ... } } The same should also be done for Scenario #3. (Really, Scenario #3 is Scenario #1 with a larger scope for `main`, but the lifetime of the objects is ~identical. I'd be inclined to use Scenario #1 over Scenario #3 just because it limits the scope of the variables, but this will have ~no impact on how long the objects live before collection.) This is the standard advice for any IDisposable type, really, e.g. FileStream. Java.Lang.Object.Dispose() releases the Java side object ~immediately, thus allowing GCs to be faster than they would otherwise (as we support cross-VM object cycles, but they impose a time/memory cost -- objects in cycles may have longer lifetimes than you might normally expect -- so if you know you don't need the Java object anymore, disposing of it will allow both GCs to do better.) The second question: how "big" is Class_Master_Main? If it's a "small" object, then keeping it around in memory ~forever shouldn't be a problem (Scenario #2). If it's sizeable, then you may want to release it sooner so that memory can be used elsewhere (Scenario #1). - Jon _______________________________________________ Monodroid mailing list [email protected] UNSUBSCRIBE INFORMATION: http://lists.ximian.com/mailman/listinfo/monodroid _______________________________________________ Monodroid mailing list [email protected] UNSUBSCRIBE INFORMATION: http://lists.ximian.com/mailman/listinfo/monodroid
