You want a garbage collection model for PDF object handling - it's how it is done by EVERY SINGLE PDF library out there...
Objects belong to a document - they can't be shared across documents. They need to be "rooted" to the document in question. Some libraries take this to mean that when you create an object you immediately "root" it as part of creation, while other let you create "on the fly" and then attach. Each has pros and cons... Leonard -----Original Message----- From: pdf-devel-bounces+lrosenth=adobe....@gnu.org [mailto:pdf-devel-bounces+lrosenth=adobe....@gnu.org] On Behalf Of Juan Pedro Bolivar Puente Sent: Tuesday, February 10, 2009 10:11 PM To: jema...@gnu.org Cc: pdf-devel@gnu.org Subject: Re: [pdf-devel] Object layer API > When we save an object document (using pdf_obj_doc_save) a garbage > collector is invoked on the objects of the saved document. The garbage > collector implements a sweep-mark process that, using the document > root dictionary as the root, marks any reachable object. Then, in the > sweep phase, every object not marked is collected. > > The 'reference weakness' is a property of both dictionary and array > entries: > > - If the entry is declared as a 'weak reference' then the object > contained in that entry is not marked when the container object is > marked. > > - If the entry is declared as a 'strong reference' (= not weak) then > the object contained in that entry is always marked, even if the > container object is going to be collected and there are not more > references to the object in the document. > I have only heard of weak/strong references in the context of reference counting and can't understand very well their need on this context. Also, I still can't understand very well the need for a garbage collector, but I also have admit that I haven't read deeply the object/document parts of the PDF specification. Isn't it ok to give the library user the responsibility to free the unused objects? Actually, if the mark-and-sweep process will use the document as root that would not allow the library user the posibility to use the object for another document (well, maybe that is fixed with your strong-reference concept). I think that garbage collection can have too many corner-cases to consider, for example, thread safety. If we used a simpler memory model -for example, referene counting- objects can be passed to a second thread with ease when the library user knows that there are no remaining references to it in the first thread, with a garbage collector this is not true -unless we make the garbage collector thread safe, adding OS dependencies that would damage the suitability of the library for embeded devices, for example. I don't know if I'm saying nonsense because I have no deep knowledge on pdf-document internals, but I think that we must think it twice before taking the decission of adding garbage collection. I will take a depper look at the specification after exams [1][2] JP [1] Actually, I don't know what the hell I am doing reading the list instead of studying :p [2] I have not forgot about my two pending tasks on Flyspray. My conscience is pricking me, I will go back to work ASAP.