• 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: Reference Count Underflow when Writing PDF
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reference Count Underflow when Writing PDF


  • Subject: Re: Reference Count Underflow when Writing PDF
  • From: "K. Darcy Otto" <email@hidden>
  • Date: Wed, 15 Jul 2009 18:25:30 -0700

In an effort to get out of this problem, I also thought I might just take a data representation of the PDFDocument object, and write the data to a file. I get the same problem. Here is what I tried, substituting for "[savedDoc writeToFile:@"newFile.pdf"]" below:

NSData *myData = [savedDoc dataRepresentation];
[myData writeToFile:@"newfile.pdf" options:0 error:&error];

The malloc error is triggered on the -dataRepresentation line.

So, three questions:

(1) Contrary to my first message, it appears to me now that PDFDocument inherits from NSObject. So, i shouldn't have to do any special memory management, right?

(2) The malloc error doesn't seem to stop the program, and everything is written to the appropriate file. Can I just leave the code as it is and ignore the error, or will it eventually catch up with me?

(3) Is there another way to do what I've tried to do, I guess not using PDFDocument (if that is indeed the culprit, and not my own code)?

Thanks,

Darcy

On 15-Jul-09, at 2:00 PM, K.Darcy Otto wrote:

I have a PDF that I've loaded, combined with another PDF, and now I'm ready to save the result as a new file. My program is using garbage collection, but I understand that PDFKit is not garbage collected. The problem is that I get reference count underflow error when writing the PDF. Here is some code that is shorter, but creates the same problem I'm having:

// Get PDF from disc
NSData *savedData = [[NSData alloc] initWithContentsOfFile:@"oldfile.pdf" options:0 error:&error];
PDFDocument *savedDoc = [[PDFDocument alloc] initWithData:savedData];


// Write saveDoc to file
[savedDoc writeToFile:@"newfile.pdf"];

Actually, there is no problem when writing the file: newfile.pdf is intact after the operation. But I get the following error in the console:

malloc: reference count underflow for 0x13464c0, break on auto_refcount_underflow_error to debug.

And when I break on auto_refcount_underflow, I get the following stack:

#0 0x94721a40 in auto_refcount_underflow_error
#1 0x9472d8e4 in Auto::Zone::dec_refcount_small_medium
#2 0x9472d9b0 in Auto::Zone::block_decrement_refcount
#3 0x931da50c in CFRelease
#4 0x904bfe4c in -[PDFDocument(PDFDocumentInternal) writeToConsumer:withOptions:]
#5 0x904bd9fc in -[PDFDocument writeToURL:withOptions:]
#6 0x904bd97c in -[PDFDocument writeToFile:withOptions:]
#7 0x00006b60 in -[MyDocument openPanelDidEnd:returnCode:contextInfo:] at MyDocument.m:495


Now, #3 suggests there is a release going on that shouldn't be; or at least there should be an extra retain in my code. But when I add "CFRetain(savedDoc);" before writing the file, the error still persists. I've read the Semantics section of Using Core Foundation with Garbage Collection, but I don't see a solution to this problem there (I'm not saying it's not there, just that I don't quite see it). Any help would be greatly appreciated.
_______________________________________________


Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Reference Count Underflow when Writing PDF
      • From: Bill Bumgarner <email@hidden>
References: 
 >Reference Count Underflow when Writing PDF (From: K.Darcy Otto <email@hidden>)

  • Prev by Date: Re: Japanese Language
  • Next by Date: Re: Dictionary interface
  • Previous by thread: Reference Count Underflow when Writing PDF
  • Next by thread: Re: Reference Count Underflow when Writing PDF
  • Index(es):
    • Date
    • Thread