I'm developing some cross-platform software which is intended to run on mobile devices. Both iOS and Android provide low memory warnings. I plan to make a wrapper class that will free cached resources (like textures) when low memory warnings are issued (assuming the resource is not in use). If the resource returns to use, it'll re-cache it, etc... I'm trying to think of what this is called. In .Net, it's similar to a "weak reference" but that only really makes sense when dealing with garbage collection, and since I'm using c++ and shared_ptr, a weak reference already has a meaning which is distinct from the one I'm thinking of. There's also the difference that this class will be able to rebuild the cache when needed. What is this pattern/whatever is called?

Edit: Feel free to recommend tags for this question.

  • a pool is what comes to mind – ratchet freak Jun 28 '13 at 23:10
  • Microsoft calls it "flushing the cache," and it's done to free memory, but it's typically referred to the process of writing the cache out to disk so that the memory can be reclaimed. See technet.microsoft.com/en-us/library/cc722473.aspx – Robert Harvey Jun 28 '13 at 23:13
  • @ratchetfreak I don't necessarily have a limited number of buckets to use, and the items themselves may be of dramatically different size. I just gotta release whatever I can when the OS tells me to. – Brent Jun 29 '13 at 0:22
  • another term would be volatile, I've seen it used in exactly this context – ratchet freak Jun 29 '13 at 0:26
  • I've seen sweeper used as terminology for that purpose in a couple different Rails and Django efforts. – JustinC Jun 29 '13 at 5:22

One term used for this is "Scavenger", though I've mostly seen it in the context of Microsoft technologies. See here in the ASP.NET Caching Overview page:


Scavenging is the process of deleting items from the cache when memory is scarce. Items are removed when they have not been accessed in some time or when items are marked as low priority when they are added to the cache.

And here's a definition from Microsoft's Caching in WinINet page:

The cache scavenger periodically cleans items from the cache. If an item is added to the cache and the cache is full, the item is added to the cache and the cache scavenger is scheduled.

So if you have an object whose task it is to free cached items when resources are low, it would be a Scavenger. You might have several scavenging strategies - Biggest First, Earliest First, etc., each implemented by a different Scavenger.

  • Since it's a template class I think I'll call it (rename it to, at this point) Scavengable<whatevs>. The constructor is also a template that accepts parameters that will be passed to the constructor when the object needs to (re)created. Thanks for the tip. – Brent Jun 30 '13 at 3:16

It is called a ... Cache. :-). Seriously, intelligently flushing it is just as important to a good cache implementation than intelligently filling it.

But your example is not really a cache, since it is not optional. A texture MUST be loaded before it can be rendered. (I would use the terms load and unload in this case).

So I imagine a class:

  • That is asked to make sure a texture image is loaded, every time it is used.
  • That loads the image from the correct storage (eg. A certain resource folder)
  • To keep track of texture usage patterns.
  • which can be asked to unload textures, based on these usage patterns.

Then that would be called a TextureLoader to me (short for TextureLoaderUnloader)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.