Passing strings to threads and memory leaks
Passing strings to threads and memory leaks
- Subject: Passing strings to threads and memory leaks
- From: Chuck Rice <email@hidden>
- Date: Thu, 6 May 2004 16:56:33 -0700
I have a chunk of code that sets a field to be sent to a Liquid Crystal Display and to a window. On thread sets the value using the following method. Another thread updates the displays. I am leaking memory because of the retain for theData, so I tried to use a temp field to swap the previous string and release it. But I am still leaking memory. Where am I going wrong. I just barely have my head around the memory allocation thing, so a remedial explanation would not be unwelcome. If I change the retain to autorelease, I crash when the method ends. Help! -Chuck-
//-----------------------------------------------------------------------
// setDisplayLine:(int)number to:(char *)data atx:(int)x aty:(int)y
//-----------------------------------------------------------------------
- (void)setDisplayLine:(int)ident to:(char *)data
{
NSString *theData = [[[NSString alloc] initWithCString:data] retain];
NSString *temp;
if (ident > MAXFIELDS) {ident = MAXFIELDS;}
if (ident < 1) {ident = 1;}
temp =displayField[ident].data;
displayField[ident].font = 3;
displayField[ident].data = theData;
displayField[ident].displayNeedsUpdate = TRUE;
iScreenNeedsUpdate = TRUE;
[temp release];
//NSLog(@"Field=%d Data=%s",ident,data);
}
--
Fight Spam! Join CAUCE! ==
http://www.cauce.org/
_______________________________________________
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.