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
Post a Comment