Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Objective-c > Details about t...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 5 Topic 947 of 1009
Post > Topic >>

Details about the the garbage collection process

by ActiveMan <basurero@[EMAIL PROTECTED] > Jan 13, 2008 at 09:28 PM

Hello, there are two questions related to the garbage collection that I 
have been investigating but I'm not capable of understanding.

1) With regards to local variables, according to the do***entation 
__strong references are those whose life cycle is controlled by the 
garbage collector. The compiler allows marking as __strong local 
variables of fundamental types and local pointer to non-Objective-C 
objects without warnings:

__strong int i=4; // No warning
__strong char* data = (char*)malloc(512); // No warning
__strong Point* p = [[Point alloc] init]; // No warning

That is, the garbage collector manages the life cycle of these 
variables. However, it emits a warning when those variables are marked 
as __weak:

__weak int i=4; // Warning
__weak char* data = (char*)malloc(512); // Warning
__weak Point* p = [[Point alloc] init]; // Warning

The warning is always: "__weak attribute cannot be specified on a local 
object declaration"

Hence, how can we avoid that the garbage collector copes with the life 
cycle of a local variable? Does it means that the memory related to 
local variables must be always managed by the garbage collector when 
the garbage collector is enabled, that is, it's not possible to make a 
weak reference using a local variable? And, why the compiler allows 
declaring int or char* types as __strong?

2) The compiler allows to create __strong and __weak global object 
pointers without complaint, but in both cases the related object 
receives the finalize method call when the variable is nilled, that is:

__weak Point* pp; // Global variable

int main (int argc, const char * argv[]) {
    pp = [[Point alloc] initWithX:1 y:1];
    pp = nil;
    [[NSGarbageCollector defaultCollector] collectExhaustively]; // 
Executes finalize over pp
    return 0;
}

This is not congruent with the semantics of __weak that the 
do***entation provides because the collector must not finalize __weak 
pointers.
 




 5 Posts in Topic:
Details about the the garbage collection process
ActiveMan <basurero@[E  2008-01-13 21:28:34 
Re: Details about the the garbage collection process
Reinder Verlinde <rein  2008-01-13 23:22:32 
Re: Details about the the garbage collection process
ActiveMan <basurero@[E  2008-01-27 13:28:02 
Re: Details about the the garbage collection process
Reinder Verlinde <rein  2008-01-27 18:06:05 
Re: Details about the the garbage collection process
Greg Parker <gparker@[  2008-01-14 13:59:30 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 18:18:25 CDT 2008.