Hi,
I wrote a program that does the following:
1) It reads in a text file line by line using straight C:
2) Using Cocoa, it creates and evaluates data from the line.
3) If the data seems fitting, it writes the line to a file, if not, the line gets discarded.
The text file is pretty big (almost 1GB). My code works, but using Activity Monitor, I found that it constantly allocates memory (about 4MB per second). I thought "Oh, there must be a leak", but Leaks from Instruments doesn't find any leak. Using Object Allocations from Instruments, I discovered that most of the allocations are done by CFString and NSData. I checked in my code, but I release all objects fine.
How does one go about solving such a problem? I have no idea where all those allocations are done, and why some objects are apparently not released. Have you ever encountered such a problem, and if yes, how did you solve it? Are there any tutorials on Instruments and how to use it to find problems?
Thanks for any help!
- ranguvar
(P.S.: I'm sorry I can't post the code, it's too much and proprietary...)
I wrote a program that does the following:
1) It reads in a text file line by line using straight C:
Code:
NSString* readLineAsNSString(FILE *file) {
char buffer[2048];
NSString *result = [[NSString alloc] init];
int charsRead;
do {
if(fscanf(file, "%2047[^\n]%n%*c", buffer, &charsRead) == 1) {
char newbuffer[2048];
int ofs = 0;
for (int i = 0; i < (2048-ofs); i++) {
// The "accent aigue" fix ;)
if (buffer[i] == '\351') {
newbuffer[i+ofs] = '\303';
newbuffer[i+1+ofs] = '\251';
ofs++;
}
else {
newbuffer[i+ofs] = buffer[i];
}
}
result = [NSString stringWithUTF8String:newbuffer];
}
else
break;
} while(charsRead == 2047);
return result;
}
2) Using Cocoa, it creates and evaluates data from the line.
3) If the data seems fitting, it writes the line to a file, if not, the line gets discarded.
The text file is pretty big (almost 1GB). My code works, but using Activity Monitor, I found that it constantly allocates memory (about 4MB per second). I thought "Oh, there must be a leak", but Leaks from Instruments doesn't find any leak. Using Object Allocations from Instruments, I discovered that most of the allocations are done by CFString and NSData. I checked in my code, but I release all objects fine.
How does one go about solving such a problem? I have no idea where all those allocations are done, and why some objects are apparently not released. Have you ever encountered such a problem, and if yes, how did you solve it? Are there any tutorials on Instruments and how to use it to find problems?
Thanks for any help!
- ranguvar
(P.S.: I'm sorry I can't post the code, it's too much and proprietary...)