summaryrefslogtreecommitdiff
path: root/source/gprf
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2016-09-15 16:37:42 +0100
committerRobin Watts <robin.watts@artifex.com>2016-09-16 14:00:32 +0100
commit3de83b0d7a679c2c91587718c1c273775b99e8dd (patch)
tree72a42a88b82c5c3d4a30c52d4df370bb0700fb38 /source/gprf
parent3a1ae9b3db655efc98965bcc82ad545f6572158d (diff)
downloadmupdf-3de83b0d7a679c2c91587718c1c273775b99e8dd.tar.xz
Extend store to cope with references used in keys.
The store is effectively a list of items, where each item is a (key, value) pair. The design is such that we can easily get into the state where the only reference to a value is that held by the store. Subsequent references can then be generated by things being 'found' from within the store. While the only reference to an object is that held by it being a value in the store, the store is free to evict it to save memory. Images present a complication to this design; images are stored both as values within the store (by the pdf agent, so that we do not regenerate images each time we meet them in the file), and as parts of the keys within the store. For example, once an image is decoded to give a pixmap, the pixmap is cached in the store. The key to look that pixmap up again includes a reference to the image from which the pixmap was generated. This means, that for document handlers such as gproof that do not place images in the store, we can end up with images that are kept around purely by dint of being used as references in store keys. There is no chance of the value (the decoded pixmap) ever being 'found' from the store as no one other than the key is holding a reference to the image required. Thus the images/pixmaps are never freed until the store is emptied. This commit offers a fix for this situation. Standard store items are based on an fz_storable type. Here we introduce a new fz_key_storable type derived from that. As well as keeping track of the number of references a given item has to it, it keeps a separate count of the number of references a given item has to it from keys in the store. On dropping a reference, we check to see if the number of references has become the same as the number of references from keys in the store. If it has, then we know that these keys can never be 'found' again. So we filter them out of the store, which drops the items.
Diffstat (limited to 'source/gprf')
-rw-r--r--source/gprf/gprf-doc.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/source/gprf/gprf-doc.c b/source/gprf/gprf-doc.c
index 5ca14aea..56570db0 100644
--- a/source/gprf/gprf-doc.c
+++ b/source/gprf/gprf-doc.c
@@ -467,7 +467,7 @@ fz_new_gprf_image(fz_context *ctx, gprf_page *page, int imagenum, fz_off_t offse
h = GPRF_TILESIZE;
}
- FZ_INIT_STORABLE(&image->super, 1, fz_drop_image_gprf_imp);
+ FZ_INIT_KEY_STORABLE(&image->super, 1, fz_drop_image_gprf_imp);
image->super.w = w;
image->super.h = h;
image->super.n = 4; /* Always RGB + Alpha */