• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: leek in componentsSeparatedByString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: leek in componentsSeparatedByString


  • Subject: Re: leek in componentsSeparatedByString
  • From: John Haager <email@hidden>
  • Date: Mon, 26 Aug 2002 07:57:11 -0700

Your apparent memory leak is not really a leak. It's just the build up of the Autoreleased strings and arrays from your function. If you're concenered about it, you should probably create an autorelease pool right before the while loop, then release it every 100th or so time through the loop. This will keep the size of the autorelease pool down and the memory footprint of your app won't be nearly as large.

John

On Monday, August 26, 2002, at 07:35 AM, David Burris wrote:

*This message was transferred with a trial version of CommuniGate(tm) Pro*
I am trying to create a function that will read through text files, using the componentsSeparatedByString function to split the lines into words. however when i run my test code on a large (68,000 lines) file, i notice a fair bit of memory leak from the componentsSeparatedByString call. here is my test code. If i try to release the 'words' in the loop then i get a signal 10 (SIGBUS) error when i run it.

Any suggestions would be greatly appreciated.



#import <Foundation/Foundation.h>
#import <tester.h>

int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

tester * c1 = [tester alloc];

[c1 infile:@"hackdemomedow2.rib" outfile:@"temp.rib"];

[pool release];
return 0;
}



#import "tester.h"
@implementation tester

- (void)infile:(NSString *)infile outfile:(NSString *)outfile {
NSString* firstWord;
//NSMutableArray* words;// = [[[NSMutableArray alloc] init] autorelease];

char* infilename = [infile cString];
char* outfilename = [outfile cString];
char temp[1001];
FILE* inRIB;
FILE* outRIB;
char* outf;
inRIB = fopen(infilename, "r");
outRIB = fopen(outfilename, "w");

NSLog(@"infilename = %@", [NSString stringWithCString:infilename]);
NSLog(@"outfilename = %@", [NSString stringWithCString:outfilename]);

while (fgets(temp, 1000, inRIB) != NULL){

NSString* currentline = [[NSString stringWithCString:temp]autorelease];
NSMutableArray* words = [[currentline componentsSeparatedByString:@" "]mutableCopy];

//[words release];
//words = nil;

[currentline release];
//currentline = nil;

//free(temp);
}

fclose(inRIB);
}
_______________________________________________
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.


-> John Haager <-
_______________________________________________
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.

  • Prev by Date: QT movie info
  • Next by Date: Leak in NSFont (10.2) or am I missing something?
  • Previous by thread: Leak in NSFont (10.2) or am I missing something?
  • Next by thread: Re: leek in componentsSeparatedByString
  • Index(es):
    • Date
    • Thread