1: In iPhone memory management, when malloc is used to allocate memory on the heap, the corresponding free heap memory should be used instead of the 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-& gt; innerItem = (char *) malloc (1024 );
[MemoryArray addObject: item];
[Item release];
Free (item-> innerItem );
Free (item );
}
[MemoryArray removeAllObjects];
}
II: If CFHTTPMessageRef is used for HTTP Communication Development in the iPhone, Content-Length Content is not included in the default header, and the display settings are required. The Code is as follows:
NSString * contentLen = [[NSString alloc] initWithFormat "% d", [bodyData length];
CFHTTPMessageSetHeaderFieldValue (myRequest,
CFSTR ("Content-Length"), (CFStringRef) contentLen );
CFDataRef mySerializedRequest = CFHTTPMessageCopySerializedMessage (myRequest); // serialize the request
The above code is worth noting that CFSTR is a macro in the iPhone and cannot dynamically set the Content-Length for it. For example, the following code cannot be compiled:
CFHTTPMessageSetHeaderFieldValue (myRequest,
CFSTR ("Content-Length"), CFSTR ([contentLen UTF8String]);