gonzalesblanco
gonzalesblanco

Reputation: 15

Must non-pointer instance variables be released in dealloc?

Do I have to call release in the dealloc method of a class for non-pointer variables?

e.g.

@interface myClass : NSObject {

    BOOL isDirty; // do i have to release this?
    NSInteger hoursSinceStart; // and this?

    NSDate *myDate; // i will release the pointer in dealloc
}

@property (assign, nonatomic) NSInteger hoursSinceStart; // property to release?

@property (assign, nonatomic) BOOL isDirty; // property to release?
@end

Upvotes: 0

Views: 315

Answers (3)

Chuck
Chuck

Reputation: 237110

Two things:

  1. You only need to retain and release objects. BOOLs and NSIntegers are not objects, they're primitives.

  2. You generally shouldn't call release for any assign property, because you haven't retained it — and of course assign is the only type that makes sense for primitives like NSIntegers or BOOLs, since you can't retain them in the first place.

Upvotes: 4

Tatvamasi
Tatvamasi

Reputation: 2547

You will all release objects that extend NSObjects (or implement NSObject protocol).
please read http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html for better understanding of memory management.

Upvotes: 0

Chazbot
Chazbot

Reputation: 1890

You don't need to release your BOOL or NSInteger. As it turns out, an NSInteger is just a typedef for an int (via is it necessary to release a NSInteger in iphone? )

Upvotes: 0

Related Questions