• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
After Autoreleasing Still Getting Leaked
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

After Autoreleasing Still Getting Leaked


  • Subject: After Autoreleasing Still Getting Leaked
  • From: Bing Li <email@hidden>
  • Date: Thu, 16 Jun 2011 00:02:04 +0800

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

  • Follow-Ups:
    • Re: After Autoreleasing Still Getting Leaked
      • From: "Gary L. Wade" <email@hidden>
    • After Autoreleasing Still Getting Leaked
      • From: Bing Li <email@hidden>
    • Re: After Autoreleasing Still Getting Leaked
      • From: Scott Ribe <email@hidden>
  • Prev by Date: Re: Interface item validation through first responder
  • Next by Date: Re: After Autoreleasing Still Getting Leaked
  • Previous by thread: Re: Copying files with authorization; best choice?
  • Next by thread: Re: After Autoreleasing Still Getting Leaked
  • Index(es):
    • Date
    • Thread