where's this getting called? Is it getting called from a timer or
button press or other event, or do you do a whole load of these in a
loop?
It seems to me that everything you have init'ed you have released
again, however surface is autoreleased, so it won't actually get
dealloced until the innermost autoreleasepool is drained. If you're
calling this function in a loop then you're not getting to that pool
drain and you're piling up memory.
But you don't need to guess, fire up instruments, run with object
allocations, that will very quickly show you where your memory is
going. If you have some unbalanced release I didn't see here, you'll
see it there, if you're piling up on an autorelease pool you'll see
that too as the stack trace for the memory (if you enable the right
options) will show you the last thing which happened is autorelease.
On 07-Sep-2009, at 7:45 PM, DairyKnight wrote:
Hi all,
I keep on getting weird malloc errors with the following code, first
from
ATSFontManager, and then:
FooProgram(1343,0xa01e1720) malloc: *** mmap(size=30855168) failed
(error
code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
2009-09-07 19:37:17.606 KindPDF[1343:10b] *** NSCopyMemoryPages
(0xfc18a000,
0x0, 30851072) failed
It seems to me that somewhere I have a memory leak, but I just
cannot figure
out where.
What the function does is to take in a PDFPage and crop according to
some
cropRect and scale down to
render the page on some surface with arbitrary geometry.
The program fails after processed for around 400 images with a
device size
of 786x1144 and RENDER_SCALE_FACTOR
of 2. MAX_POINTS of 300 (This constant is to make the cropRect units
percetages)
Hope someone could help me.... this program has been making me mad for
around a week... Thanks.
-(NSImage *) generatePage:(PDFPage *) page withCropRect:(CropRect)
cropRect
onDevice:(NSSize) deviceSize
{
NSRect originalPageMediaBox = [page
boundsForBox:kPDFDisplayBoxMediaBox];
NSRect croppedPageMediaBox = NSMakeRect((float)
originalPageMediaBox.size.
width * (float)cropRect.left / MAX_POINTS,
(float)originalPageMediaBox.size.height * (float)cropRect.bottom /
MAX_POINTS,
originalPageMediaBox.size.width * (1.0 - (float)cropRect.horiCropped /
MAX_POINTS),
originalPageMediaBox.size.height * (1.0 - (float)
cropRect.vertCropped /
MAX_POINTS));
float croppedPDFAspectRatio = croppedPageMediaBox.size.height /
croppedPageMediaBox.size.width;
float deviceAspectRatio = deviceSize.height / deviceSize.width;
float width, height;
if (croppedPDFAspectRatio > deviceAspectRatio)
{
height = deviceSize.height;
width = height / croppedPDFAspectRatio;
} else
{
width = deviceSize.width;
height = width * croppedPDFAspectRatio;
}
width = width * RENDER_SCALE_FACTOR;
height = height * RENDER_SCALE_FACTOR;
//
// Crop the PDF Page
//
NSPDFImageRep *pdfImg = [NSPDFImageRep imageRepWithData:[page
dataRepresentation]];
NSSize pageSize = NSMakeSize(width / (1.0 - cropRect.horiCropped /
MAX_POINTS), height / 1.0 - cropRect.vertCropped / MAX_POINTS);
NSImage *pdfPage = [[NSImage alloc] initWithSize:pageSize];
[pdfPage lockFocus];
[pdfImg drawInRect:[pdfPage rect]];
[pdfPage unlockFocus];
NSBitmapImageRep *pdfPageRep = [NSBitmapImageRep imageRepWithData:
[pdfPage
TIFFRepresentation]];
NSImage *rasterizedPage = [[NSImage alloc] initWithSize:NSMakeSize
(width,
height)];
[rasterizedPage lockFocus];
[[NSColor whiteColor] setFill];
NSRectFill(NSMakeRect(0, 0, width, height));
[pdfPageRep drawAtPoint:NSMakePoint(-1 * width * cropRect.left /
MAX_POINTS,
-1 * height * cropRect.bottom / MAX_POINTS)];
[rasterizedPage unlockFocus];
[pdfPage release];
//
// Scale down to original size
//
NSImage *surface = [[[NSImage alloc] initWithSize:NSMakeSize(width /
RENDER_SCALE_FACTOR, height / RENDER_SCALE_FACTOR)] autorelease];
[surface lockFocus];
[rasterizedPage drawInRect:[surface rect] fromRect:[rasterizedPage
rect]
operation:NSCompositeCopy fraction:1];
[surface unlockFocus];
[rasterizedPage release];
return surface;
}
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/rols%40rols.org
This email sent to [email protected]
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]