0
 Profile *myProfile= [[Profile alloc]init];

[myProfile setName:@"Jhon Applesead"];
[myProfile setCompany:@"Apple"];

[myProfile release];

NSLog(@"Name is %@", [myProfile name]);

Log is

2013-02-28 15:41:36.866 Practice[8124:303] Name is Jhon Applesead

3 Answers3

3

When you send a release message on an object, the object is actually not being removed from the memory. The release message simply decrements the reference count by one only. If the reference count is zero the object is marked as free. Then the system remove it from the memory. Until this deallocation happens you can access your object. Even if you release the object your object pointer still points to the object unless you are assigning nil to the pointer.

Anil Varghese
  • 42,757
  • 9
  • 93
  • 110
1

I Think that's because you didn't release name and company inside the dealloc of Profile

Hossam Ghareeb
  • 7,063
  • 3
  • 53
  • 64
1

release does not necessarily destroy objects. It simply decrements the retain count by one. And if that retain count ever gets to zero, only then the object is deallocated. So this code works because a release happens but without triggering a dealloc.

For more details, see Apple's memory management guide.

rusev
  • 1,880
  • 2
  • 17
  • 14