1:In Memory Management of the iPhone, when malloc is used to allocate memory on the heap, it is necessary to use the corresponding free release heap memory instead of 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-& 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 contained 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 length for it. For example, the following code cannot be compiled:
Cfhttpmessagesetheaderfieldvalue (myrequest,
Cfstr ("Content-Length"), cfstr ([contentlen utf8string]);