IPhoneDevelopment LearningMemoryRelease Notes are described in this article,IPhone memoryManagement, involving malloc allocation on the heapMemoryYou need to use the corresponding free to release the heap memory, rather than simply release related objects. The following code:
- @interface MemoryTestProjViewController : UIViewController {
- @public
- NSMutableArray * memoryArray;
- }
-
- @end
- @interface MemoryTestProjItem : NSObject
- {
- @public
- char * innerItem;
- }
- @end
During initialization, The innerItem pointer allocates memory on the heap space, but remember to call the free function to release the heap space. The Code is as follows:
- - (void)viewDidUnload {
- // Release any retained subviews of the main view.
- // e.g. self.myOutlet = nil;
- memoryArray = [[NSMutableArray alloc] initWithCapacity:10];
- for(int i = 0;i < 1024;i++)
- {
- MemoryTestProjItem* item = [[MemoryTestProjItem alloc] init];
-
- item->innerItem = (char*)malloc(1024);
-
- [memoryArray addObject:item];
- [item release];
- free(item->innerItem);
- free(item);
- }
- [memoryArray removeAllObjects];
- }
Summary:IPhoneDevelopment LearningMemoryThe release notes are described. I hope this article will help you.