Thread: Objective C Leaking

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    I think that what you have to do is release name explicitly in the destructor:
    Code:
    -(void) dealloc
    {
      printf("Calling dealloc\n");
      [name release]
      [super dealloc];  
    }
    EDIT: Was this one of the tutorials you looked at? It looks fairly decent for someone with previous programming experience.
    Consider this post signed

  2. #2
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Quote Originally Posted by bernt View Post
    I think that what you have to do is release name explicitly in the destructor:
    Code:
    -(void) dealloc
    {
      printf("Calling dealloc\n");
      [name release]
      [super dealloc];  
    }
    EDIT: Was this one of the tutorials you looked at? It looks fairly decent for someone with previous programming experience.
    Thanks. And yes, that was one of the tutorial I looked at and it was quite decent although lacking loads of stuff (I still have no idea what NSNumber really is in regard to integers or what you can do with an NSString and how).

    Anyways, I tried what you said, but it didn't matter - still the same error. I don't think it should anyway, the setter would retain nil (doing nothing) and autorelease the old name. That's what the tutorial told me anyway (the one you linked me to).

    But I did some testing and I found out that the problem is the getter of the name: apparently it adds one to the retain count. Does that mean I have to release everything I get from the getter? Quite dreadful if you want to do simple things like printing it in this case. I mean - if I'd want to actually retain it I'd call it myself in that case, right?

    So what's going on here? Why's the getting incrementing the retain count? (I actually printed it to verify - it was 2 at the dealloc function.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. STL leaking?
    By g4j31a5 in forum C++ Programming
    Replies: 3
    Last Post: 04-03-2009, 01:47 AM
  2. C/C++ Objective questions
    By prayami in forum C++ Programming
    Replies: 22
    Last Post: 04-08-2008, 12:58 PM
  3. Objective C
    By Shadow12345 in forum C++ Programming
    Replies: 19
    Last Post: 01-15-2003, 01:40 PM
  4. Programming Objective C in Mac OSX
    By MacUser in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 10-17-2002, 08:12 AM
  5. gcc and objective c
    By Captain in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 10-13-2002, 03:03 PM