In iPhone Development You must do your own memory management through reference counting, using -retain, -release and -autorelease.
Retain Count rules
- Within a given block, the use of
-copy,-allocand-retainshould equal the use of-releaseand-autorelease. - Objects created using convenience constructors (e.g. NSString's stringWithString) are considered autoreleased.
- Implement a
-deallocmethod to release the instance variables you own.
| Method | Description |
|---|---|
-retain | increases the reference count of an object by 1 |
-release | decreases the reference count of an object by 1 |
-autorelease | decreases the reference count of an object by 1 at some stage in the future |
-alloc | allocates memory for an object, and returns it with retain count of 1 |
-copy | makes a copy of an object, and returns it with retain count of 1 |
No comments:
Post a Comment