[SOLVED]NSBitmapImageRep representationUsingType crashes.....
[SOLVED]NSBitmapImageRep representationUsingType crashes.....
- Subject: [SOLVED]NSBitmapImageRep representationUsingType crashes.....
- From: "Juan P. Pertierra" <email@hidden>
- Date: Wed, 25 Jan 2006 19:07:23 -0500
On the line which saves the file:
[[imageRep representationUsingType:imageFileType properties:nil]
writeToFile:[NSString stringWithFormat:@"./%s_d.%s", takeName,
thisFrame, [fileExtension cString]] atomically:NO];
representationUsingType returns an autoreleased NSData object.
Because this function was called from a detached thread with its own
autorelease pool, all of these NSData objects were kept over all the
calls to the function.
I solved(i think) the problem by creating another autorelease pool
before the for loop, and releasing it afterwards, which releases all
the NSData objects used in the for loop.
On Jan 25, 2006, at 5:13 PM, Juan P. Pertierra wrote:
There is a detached thread in my cocoa app which simply takes image
data from a continuous block of RGB images already in memory, and
writes each image to disk in a separate file. I am using
initWithBitmapDataPlanes to assign the RGB data to an NSBitmapRep,
write the image to disk, and I then release the instance, then use
the init method again for the next image. I am using the following
line to write the image to disk:
[[imageRep representationUsingType:imageFileType properties:nil]
writeToFile:[NSString stringWithFormat:@"./%s_d.%s", takeName,
thisFrame, [fileExtension cString]] atomically:NO];
The code runs for a while, but eventually representationUsingType:
crashes. If I look at the activity monitor, I also notice that
this line seems to consume a very large amount of RAM. if I take
this line out, then everything executes normally, without crashing
or abnormal memory consumption. Of course, the files are then not
written to disk which is what I need.
Below is the relevant code:
ptrFrame = outputBuffer->data; //Pointer to first image
NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes: (unsigned char **)&ptrFrame
pixelsWide: 1280
pixelsHigh: 720
bitsPerSample: 8
samplesPerPixel: 3
hasAlpha: NO
isPlanar: NO
colorSpaceName: NSCalibratedRGBColorSpace
bytesPerRow: (1280 * 3)
bitsPerPixel: 24];
for(thisFrame = firstFrame; thisFrame < (firstFrame + frames);
thisFrame++)
{
[[imageRep representationUsingType:imageFileType properties:nil]
writeToFile:[NSString stringWithFormat:@"./%s_d.%s", takeName,
thisFrame, [fileExtension cString]] atomically:NO];
[imageRep release]; //Release object, image already written to disk
ptrFrame = (unsigned char *)ptrFrame + (FRAME_SIZE * 4); //Move
pointer to next image
imageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:
(unsigned char **)&ptrFrame
pixelsWide: 1280
pixelsHigh: 720
bitsPerSample: 8
samplesPerPixel: 3
hasAlpha: NO
isPlanar: NO
colorSpaceName: NSCalibratedRGBColorSpace
bytesPerRow: (1280 * 3)
bitsPerPixel: 24];
}
[imageRep release];
{END}
Any ideas?
Thanks in advance...
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
stream.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden