Memory Leaks?
Memory Leaks?
- Subject: Memory Leaks?
- From: John MacMullin <email@hidden>
- Date: Mon, 5 Jan 2004 10:04:39 -0700
I have a test application that leaks memory. The app follows the Text
System Architecture (TSA) set forth in the Apple docs. In an effort to
be over thorough, I have wrapped every method with their own
autorelease pool and double checked the release of all objects and they
now seem to be in order. OOM still points to the [printOp
runOperation] statement, which shows lots of memory allocated but not
released. In viewing the memory allocations with other memory
programs, ie., Memory Stick and Malloc Debug, the memory usage does not
seem to leak until this statement.
First question, does the [printOp runOperation] method leak when using
the TSA?
Second, the code that generates the mutable strings for the TSA
follows. The problem are evident when processing large numbers of
records (ie., 24,000 or so) Does this approach leak?
fileFieldOne = [[NSMutableString alloc]init];
fileFieldTwo = [[NSMutableString alloc]init];
fileFieldThree = [[NSMutableString alloc]init];
fileFieldFourNumber = [[NSMutableString alloc]init];
for (i=0; i< numRows; i++) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc]init];
[self printARecord:[[self testFile]objectAtIndex:i]];
[testFile removeObjectAtIndex: i];
numRows = [[self testFile]count];
i = i -1;
[pool release];
};
attrStringFieldOne = [[NSAttributedString
alloc]initWithString:fileFieldOne attributes: centerAttribs];
[fileFieldOne release];
attrStringFieldTwo = [[NSAttributedString
alloc]initWithString:fileFieldTwo attributes: centerAttribs];
[fileFieldTwo release];
attrStringFieldThree = [[NSAttributedString
alloc]initWithString:fileFieldThree attributes: leftAttribs];
[fileFieldThree release];
attrStringFieldFourNumber = [[NSAttributedString
alloc]initWithString:fileFieldFourNumber attributes: rightAttribs];
[fileFieldFourNumber release];
- (void)printARecord:(NSArray *)record
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc]init];
[fileFieldOne appendString:[record objectAtIndex:fieldOneDef]];
[fileFieldOne appendString:@"\n"];
[fileFieldTwo appendString:[record objectAtIndex:fieldTwoDef]];
[fileFieldTwo appendString:@"\n"];
[fileFieldThree appendString:[record objectAtIndex:fieldThreeDef]];
[fileFieldThree appendString:@"\n"];
[fileFieldFourNumber appendString:[numberFormatter
stringForObjectValue:[record objectAtIndex: fieldFourNumberDef]]];
[fileFieldFourNumber appendString:@"\n"];
[pool release];
}
Third, alternative code that generates the mutable strings for the TSA
follows. Does this approach leak?
fileFieldOne = [[NSMutableString alloc]init];
fileFieldTwo = [[NSMutableString alloc]init];
fileFieldThree = [[NSMutableString alloc]init];
fileFieldFourNumber = [[NSMutableString alloc]init];
for (i=0; i< numRows; i++) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc]init];
[fileFieldOne appendString:[[[self
testFile]objectAtIndex:i]objectAtIndex:fieldOneDef]];
[fileFieldOne appendString:@"\n"];
[fileFieldTwo appendString:[[[self
testFile]objectAtIndex:i]objectAtIndex:fieldTwoDef]];
[fileFieldTwo appendString:@"\n"];
[fileFieldThree appendString:[[[self
testFile]objectAtIndex:i]objectAtIndex:fieldThreeDef]];
[fileFieldThree appendString:@"\n"];
[fileFieldFourNumber appendString:[numberFormatter
stringForObjectValue:[[[self
testFile]objectAtIndex:i]objectAtIndex:fieldFourNumberDef]]];
[fileFieldFourNumber appendString:@"\n"];
[testFile removeObjectAtIndex: i];
numRows = [[self testFile]count];
i = i -1;
[pool release];
};
attrStringFieldOne = [[NSAttributedString
alloc]initWithString:fileFieldOne attributes: centerAttribs];
[fileFieldOne release];
attrStringFieldTwo = [[NSAttributedString
alloc]initWithString:fileFieldTwo attributes: centerAttribs];
[fileFieldTwo release];
attrStringFieldThree = [[NSAttributedString
alloc]initWithString:fileFieldThree attributes: leftAttribs];
[fileFieldThree release];
attrStringFieldFourNumber = [[NSAttributedString
alloc]initWithString:fileFieldFourNumber attributes: rightAttribs];
[fileFieldFourNumber release];
Any assistance would be greatly appreciated.
John
_______________________________________________
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.