Just a quick heads-up: I've comitted my orphan collection code to CVS.
Among other things, this means that leftover gradients/markers/patterns will get automatically cleaned up when the objects that use them are deleted.
Caveats:
* this only applies to such objects created with a build of Inkscape which post-dates this commit
* not all automatically-created objects will necessarily be collected; the code that creates them needs to be updated to set the correct collection policy
* paint objects won't get collected until another editing operation takes place, since NRArenaShape currently holds onto an SPStyle for too long
Technical details:
Assuming its collection policy permits it, an object will be collected if neither it nor its descendants have any outstanding inter-document URI references (nonzero SPObject::hrefcount).
There are two "policies" for collecting orphans:
* "with-parent" - the object will only be collected if one of its ancestors is collected
* "always" - the object is always collected if unused
(a third policy might be "never", which would necessarily also prevent that object's ancestors from ever being collected; I do not plan on implementing it)
The policy in effect is determined by the inkscape:collect attribute.
Be careful with the "always" policy; it really only makes sense for "private" objects that are indirectly created behind the scenes (e.g. by selecting a fill or marker option in the GUI).
-mental