Re: Small sockets, Autorelease etc...
Re: Small sockets, Autorelease etc...
- Subject: Re: Small sockets, Autorelease etc...
- From: Richard Schreyer <email@hidden>
- Date: Sun, 26 May 2002 12:26:46 -0700
You are trying to allocate objective-c objects without an autorelease
pool in place. I suggest you read up on objc memory management (done by
reference counting).
When you autorelease an object, it gets added to the autorelease pool.
When the autorelease pool is deleted, it deletes everything in it too.
It's a nice way of being able to declare that you won't need any
particular object past the close of your current method/function.
To fix this, you need to place
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
at the beginning of your code, and
[pool release];
at the end.
Now, for some other problems in that code. Your allocating that socket
twice.
[Socket socket] returns a socket instance that is already autoreleased
for you (so you don't have to explicitly call [socket release] at the
end of the method.) Then you call [[Socket alloc] init] which allocates
a second socket that isn't autoreleased. Get rid of the second Socket
instantiation.
richard schreyer
On Sunday, May 26, 2002, at 11:54 AM, malcom wrote:
Hello at all,
I'm a cocoa newbie... I would to make an irc client using cocoa and
obj-c. I
have downloaded SmallSockets framework from sourceforge.net.
This is the code to connect. I send a initial authenticatin message for
now.
But there are some problems:
- some cocoa errors;
- the result message will be visibile only when the connection timed
out by
server.
This is the messages:
******************************************************
2002-05-26 20:52:42.021 clIRC[341] *** _NSAutoreleaseNoPool(): Object
0x8ca30 of class NSCFString autoreleased with no pool in place - just
leaking
2002-05-26 20:52:42.029 clIRC[341] *** _NSAutoreleaseNoPool(): Object
0x8ff00 of class Socket autoreleased with no pool in place - just
leaking
2002-05-26 20:52:42.357 clIRC[341] *** _NSAutoreleaseNoPool(): Object
0x6f550 of class NSConcreteMutableData autoreleased with no pool in
place -
just leaking
2002-05-26 20:52:42.358 clIRC[341] *** _NSAutoreleaseNoPool(): Object
0x93540 of class NSConcreteMutableData autoreleased with no pool in
place -
just leaking
2002-05-26 20:52:44.591 clIRC[341] *** _NSAutoreleaseNoPool(): Object
0x93600 of class NSCFString autoreleased with no pool in place - just
leaking
2002-05-26 20:52:44.591 clIRC[341] data: \\304\\026\\010\\304
*********************************************************
This is the main.c code:
*********************************************
#import <Cocoa/Cocoa.h>
#import "Socket.h"
int main(int argc, const char *argv[])
{
Socket *socket;
NSString *stringa;
NSMutableData* response;
NSString* responseString;
NS_DURING
stringa = [NSString stringWithFormat:@"NICK daniele\n\rUSER dani . .
:ciao"];
socket = [Socket socket];
socket = [[Socket alloc] init];
[socket connectToHostName: @"irc.edisontel.it" port: 6667];
[socket writeString: stringa];
response = [[[NSMutableData alloc] init] autorelease];
// [socket readData:response];
/* while ( [socket readData:response] )
{
// Read until other side disconnects
}*/
[socket readData:response];
responseString = [[[NSString alloc] initWithData:response
encoding:[NSString defaultCStringEncoding]]
autorelease];
NSLog(@"data: %s",responseString);
NS_HANDLER
NS_ENDHANDLER
return NSApplicationMain(argc, argv);
}
******************
Anyone can help me? Thanx a lot!
Bye,
malcom
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.