refcounting images (was Re: Inline Images??? [ was: Re: Graphic Images ])


Subject: refcounting images (was Re: Inline Images??? [ was: Re: Graphic Images ])
From: Paul Rohr (paul@abisource.com)
Date: Fri Apr 20 2001 - 14:08:45 CDT


At 04:43 PM 4/20/01 +0200, Paolo Molaro wrote:
>What we should fix is this, instead: try to insert an image and
>delete it from the document. Save the (empty) document and you will
>find the image data there. Repeat a few times and the document
>will grow to some MBs quickly.

Good catch. Thanks.

This is a longstanding bug, but I'm not sure it ever made it into Bugzilla.
In any event, it's obnoxious, and should certainly be fixed no later than
1.0.

One subtlety. The true fix for this requires something like a refcount
check when exporting data items, to make sure that they're currently being
used in that state of the document.

However, because we have infinite undo (within the current session), we
can't just get rid of the item from the in-memory datastore at edit time
when the last reference is removed. We also can't purge it at save time.
To see why, say we have the following sequence of actions:

  1. open a document
  2. do some typing
  3. add an image
  4. do some typing
  5. remove the image
  6. do some more typing
  7. undo to step 4
  8. undo to step 2

Saves immediately after steps 1, 2, 5, 6, *and 8* should not include that
image. Saves immediately after steps 3, 4, *and 7* should include it.

>Note also that if you insert
>the same image twice it gets in the document twice, this is bad,
>if the data is the same it should be stored only once.

This sounds plausible, too. IIRC, there might have been a screw case here,
but I forget what it was.

One possibility -- if you insert the "same" image during two different
sessions, how do you in fact know that it's the same? Scan through all the
existing images and do a bitwise comparison with each? Maintain checksums
instead and just check those?

Obvious special case -- only copy & paste is guaranteed to produce the same
image.

This should probably be filed as a separate item in Bugzilla and linked to
the one above, since they're clearly related.

Or, as always, anyone who has a good fix for both could just check it in.
:-)

Paul



This archive was generated by hypermail 2b25 : Fri Apr 20 2001 - 14:01:12 CDT