Release an object without a pointer?
- by Kai Friis
I’ve just started developing for iPhone and am trying to get my head around memory management. I made a small program that shows a map and an annotation on the map. For the annotation I made a simple class that implements the MKAnnotation protocol.
To create and add the annotation I wrote this:
[self.myMapView addAnnotation:[[MyAnnotation alloc] init]];
It worked fine until I tried to release the object. Nothing to release. This is what I would have done in C#, I guess it doesn’t work without garbage collection?
So is this the only way to do it?
MyAnnotation *myAnnotation = [[MyAnnotation alloc] init];
[self.myMapView addAnnotation: myAnnotation];
[myAnnotation release];