Dear all,

First, I appreciate so much for your replies in the past days. Those replies
help me a lot when implementing my system.

I got another problem in the following method. A byte array is used to save
data transmitted from a remote node and the size is different for each
message. I think I need to release the byte array after it is used. However,
the system got crashed if the line, free(receivedBytes), was added. So I
made a copy for the receivedMessage. But it still crashed.

One more issue is that there was no memory leaking even if I didn't add the
line, free(receivedBytes). Why?

Thanks so much for your help!

Best regards,
Bing

                        …...
                        NSInteger messageSize = [sizeString intValue];
                        char receivedBytes[messageSize];
                        while (currentByteIndex < messageSize)
                        {
                                NSAutoreleasePool *subLoopPool =
[[NSAutoreleasePool alloc] init];
                                numberBytesReceived = recv(clientSocket,
buffer, messageSize - currentByteIndex, 0);
                                if (numberBytesReceived > 0)
                                {
                                        for (int i = 0; i <
numberBytesReceived; i ++)
                                        {

 receivedBytes[currentByteIndex + i] = buffer[i];
                                        }
                                        currentByteIndex +=
numberBytesReceived;
                                }
                                else
                                {
                                        [subLoopPool drain];
                                        return;
                                }
                                [subLoopPool drain];
                        }
//                      NSString *receivedMessage = [[[[NSString alloc]
initWithBytes:receivedBytes length:currentByteIndex
encoding:NSUTF8StringEncoding] copy] autorelease];
                        NSString *receivedMessage = [[[NSString alloc]
initWithBytes:receivedBytes length:currentByteIndex
encoding:NSUTF8StringEncoding] autorelease];
                        [self NotifyMessageReceived:receivedMessage];
                        free(receivedBytes);
                        …...
_______________________________________________

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

Reply via email to