And the scope may be a larger scope than the one you define in your program, i.e., the variables in an inner block quietly be allocated/ released in an enclosing block. So you're always safe assuming the variable is good within the inner block but you can't assume it will be available for collection upon exit.

You can also assume that variables recently allocated and released will be collected first, i.e., there is locality in the collector. (Variables in cyclic dependencies would be excepted.) This is useful because it means that memory collected when you don't expect it to often shows up reallocated shortly thereafter (much tougher to bracket the problem if it were delayed indefinitely).

Overriding finalize() should tell what's really going on with aFoo (might leave you still wondering why).

        Tom


On Dec 8, 2009, at 9:53 AM, Antonio Petri wrote:

The object referenced by aFoo should only be garbage collected after the variable goes out of scope. If the editing context holds a strong reference to it, it shouldn't be garbage collected.

2009/12/8 Ricardo J. Parada <[email protected]>


Hi All,

If I have a local variable that is assigned a value and never read after that, is it possible that it may get garbage collected before the block where it was defined. For example:

        public void someMethod() {
                Foo aFoo = new Foo(editingContext());
                editingContext().saveChanges();
        }

Will aFoo live until the end of someMethod()? Or could it get garbage collected?

I'm asking because in the real app, Foo is a delegate of the editing context when it gets created and it finishes its job when the editing context saveChanges() is called. But in a non-GUI app, we believe aFoo is getting garbage collected prematurely. Those are someone else's findings but I though I should ask to see if that is right.

The documentation for NSNotificationCenter says the following:

Note: If the default NSNotificationCenter is the last object in your application with a reference to either an object registered to receive notifications or an object being observed, that object will be garbage collected.

P.S. Sorry if this is more a java question than a WebObjects question. :-)

Thanks,
Ricardo




 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/antonio.petri% 40googlemail.com

This email sent to [email protected]

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/blenko% 40martingalesystems.com

This email sent to [email protected]

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to