Re: After Autoreleasing Still Getting Leaked
Re: After Autoreleasing Still Getting Leaked
- Subject: Re: After Autoreleasing Still Getting Leaked
- From: "Gary L. Wade" <email@hidden>
- Date: Wed, 15 Jun 2011 09:25:57 -0700
There are so many fundamental issues with your coding. Rather than just throwing solutions at perceived problems, I would recommend you step back and document your justification for every line of code you write. In order to learn, you should consider this exercise to be descriptive enough to explain to a non-programmer.
- Gary L. Wade (Sent from my iPhone)
On Jun 15, 2011, at 9:02 AM, Bing Li <email@hidden> wrote:
> 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.
>
> 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 (email@hidden)
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:
This email sent to email@hidden