Dear all, I got a problem which confused me. The following method is put into NSOperationQueue so that it can run asynchronously. The method received data from a remote node and then converted the bytes to NSMutableString. This is a loop so that I set up an autorelease pool. I even set up an additional autorelease pool in case that the loop is blocked at the recv() function. However, it occasionally gets huge leaks.
Another question is that what are the states, according to which I can believe the program gets robust. I don't worry about leaks or any other issues? Most time, the current program runs well. I am even not aware that the line has a so big problem without Instruments. And, the problem does not always happen even with Instruments. In addition, according to Activity Monitor, the memory consumed by the program increased only when some new threads are added. After the threads were dead, the memory was lowered to a fixed amount. Is it fine? Thanks so much! Bing - (void) run { char buffer[1024]; ssize_t numberBytesReceived; while (true) { NSAutoreleasePool *loopPool = [[NSAutoreleasePool alloc] init]; numberBytesReceived = recv(clientSocket, buffer, 1024, 0); if (numberBytesReceived > 0) { buffer[numberBytesReceived] = '\0'; NSAutoreleasePool *subLoopPool = [[NSAutoreleasePool alloc] init]; // This line sometimes gets huge leaks (about 167.80MB, 226933 leaks). But it does not always happen // I don't understand why it gets leaked! NSMutableString *receivedMessage = [[[NSMutableString alloc] initWithBytes:buffer length:numberBytesReceived encoding:NSUTF8StringEncoding] autorelease]; [self notifyMessageReceived:receivedMessage]; [subLoopPool drain]; } else { [loopPool drain]; break; } for (int i = 0; i < 1024; i ++) { buffer[i] = '\0'; } [loopPool drain]; } if (buffer[0] != '\0') { free(buffer); } } _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com