objective c - Objects not initialized -


in objective c, can following

uiimage *myimage = [uiimage imagenamed:@"myphoto.jpg"]; variable.image = myimage; 

and works fine. object named "myimage" never initialized, , uiimage never had memory allocated , yet code still works..

can explain what's going on here?

yes, object initialised. imagenamed: method allocates , initialises object, sends autorelease message, returns memory address you. store memory address in pointer called myimage.

myimage , object 2 different things. myimage merely points @ memory location. not object itself.

you can pass around objects without assigning them variables, , can assign 1 object many variables.

consider this:

uiimage *imageone; uiimage *imagetwo;  imageone = [uiimage imagenamed:@"myphoto.jpg"]; imagetwo = imageone; 

the image wasn't copied. there 1 object in existence. both variables point it.

now consider this:

nslog(@"%@", [uiimage imagenamed:@"myphoto.jpg"]); 

you didn't assign variable. object still existed, right?


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -