Re: After Autoreleasing Still Getting Leaked
Re: After Autoreleasing Still Getting Leaked
- Subject: Re: After Autoreleasing Still Getting Leaked
- From: Tony Romano <email@hidden>
- Date: Wed, 15 Jun 2011 19:01:56 -0700
- Thread-topic: After Autoreleasing Still Getting Leaked
I state a point slightly different to Bing about the TCP issue.
TCP does NOT guarantee you will get the WHOLE PACKET on one receive call.
BEFORE you PROCESS any data, you need to know that you have ALL the data.
It may work MOST of the TIME, but there are times when it won't and your
code WILL FAIL.
When you code at the socket level, you need to be robust and know 2 Major
pieces of data.
1. Is this packet for you? Anyone can send you data on that socket but
you need to make sure the packet is something you understand. The classic
way is to wrap the data with a header with some magic number unique to
you. Checking for the magic number helps signal your code, this is
something you can understand.
2. You need to know how many bytes any particular packet contains.
Usually there is some operation code pair with the number of byte to
expect for the operation. These two additional pieces of information tell
you how much more you need to read and what operation to do on that data.
Once you have a good packet, then you can process it correctly. There are
other things you need to do to make it robust, but these are the basics.
Note, if you have only type of data between your clients, you may not need
the operation code.
I have no idea if your run method is in a thread(you better figure out how
select works). If it is, the method notifyMessage, is a black box and I
have no idea what happens to the string there. Is it retained, released,
ignored, no clue. Your leak is not in the run method. As I and others
have said before, countless times. DON¹T USE LEAKS! It's like calling the
fire dept and saying there is a fire and NOT telling them where it is.
I'm not trying to be harsh, countless people are trying to help and they
are not convinced you are listening :-).
Tony Romano
On 6/15/11 2:20 PM, "Scott Ribe" <email@hidden> wrote:
>On Jun 15, 2011, at 2:30 PM, Jens Alfke wrote:
>
>> On Jun 15, 2011, at 1:26 PM, Bing Li wrote:
>>
>>> Actually, I attempt to design P2P system using Cocoa. Meanwhile, the
>>>peer on Mac OS X must communicate with some Java systems. So I need to
>>>use sockets and transmit XML.
>>
>> Sorry to be blunt, but it¹s clear from this answer (and others) that
>>you¹re not reading the suggestions people are giving you. All you
>>responded to here was one minor question at the end of Conrad¹s message,
>>not the numbered list of five major issues.
>
>Not 100% sure, but I believe he may already have been told that he
>doesn't need to use low-level sockets just because he's communicating
>with Java...
>
>Anyway, to Bing, my last advice:
>
>- You have to follow proper memory management everywhere, not just where
>you're originally allocating objects. As has been pointed out to you
>multiple times now, your leak is not coming in the code snippet you
>posted. It's happening elsewhere, in code that uses the return value, so
>that's what you have to look at, what the consumers of that returned
>value do with it.
>
>- Given that you had two stack-smashing bugs in one small snippet of C,
>and other oddities in the code, I think you really need to read a basic
>introductory text on C.
>
>- You also don't seem to really understand how sockets work. Perhaps I'm
>wrong here, and your receivedMessage method does everything it would need
>to do in terms of assembling message fragments, if only you weren't
>potentially messing up strings because of boundary issues before you ever
>called it. (In other words, if you just appended to NSData or some such
>until you had a whole message.) But from the overall sense of your code
>and your questions, I really doubt it. So an introductory text on network
>programming is also in order (Stevens is the classic on this subject). Or
>you could use higher-level network APIs, to which I believe you were
>referred a long time ago: CFSocket, maybe NSURL depending on the
>structure of the messages you're exchanging with Java.
>
>
>--
>Scott Ribe
>email@hidden
>http://www.elevated-dev.com/
>(303) 722-0567 voice
>
>
>
>
>_______________________________________________
>
>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
>
_______________________________________________
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