Re: Memory Leaks in CocoaEcho Sample
Re: Memory Leaks in CocoaEcho Sample
- Subject: Re: Memory Leaks in CocoaEcho Sample
- From: Marco Masser <email@hidden>
- Date: Wed, 22 Oct 2008 21:05:57 +0200
I'm just building my own application based on the CocoaEcho sample
from Apple. But the CocoaEcho Client is full of memory leaks. These
leaks occur, when you select and deselect a CocoaEchoServer some
times by clicking on them and again next to them Leaked Objects are:
SCNetworkReachability
GeneralBlocks
NSCFDictionaries
NSCFData
NSCFInputStream
NSCFOutputStream
All points to the openstream: and closestream: methods but I am not
so skilled to find the error with the help of instruments and the
debugger. Does someone know if there is something wrong in the
CocoaEchoClient code or if the error is in the Cocoa frameworks
itself?
I've built a networking framework some time ago and used the CocoaEcho
example as a starting point. Some of the sample code is still present
and I just realised that I'm using the exact same -openStreams method,
just without the two -retain messages for the inputStream and
outputStream. Additionally, I just verified that doing just that in
the CocoaEcho example gets rid of the memory leaks.
According to Cocoa conventions, methods starting with -get... return
values by reference, but I can't find anything that talks about memory
management when using such methods. Therefore, I would assume the
normal rules apply and the values should be autoreleased (even though
we are not really talking about return values per se).
The streams you get by using -getInputStream:outputStream: have a
retain count of 1 and are not autoreleased. I'd say it's either a bug
in the framework or rather a weak spot in the documentation.
Marco
P.S.: I just tested NSGradient's -getColor:location:atIndex: method
(the only one I could find that returns an object by reference) and
here too, the first parameter (an NSColor **) has a retain count of 1
and is not autoreleased. I'd say there's something amiss in the docs
and the CocoaEcho sample is wrong.
_______________________________________________
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