Class TImagesCache

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type TImagesCache = class(TObject)

Description

A cache of loaded images.

The idea is that instead of Image := LoadImage(...) call Image := Cache.LoadImage_IncReference(...). Later, instead of freeing this image, call LoadImage_DecReference(Image). From your point of view, things will work the same. But if you expect to load many images from the same FileName, then you will get a great speed and memory saving, because image will only be actually loaded once. Notes:

Note that before destroying this object you must free all images, i.e. call LoadImage_DecReference for all images allocated by LoadImage_IncReference. This class is not a lousy way of avoiding memory leaks — it would be a bad idea, because it would cause sloppy programming, where memory is unnecessarily allocated for a long time. In fact, this class asserts in destructor that no images are in cache anymore, so if you compiled with assertions enabled, this class does the job of memory-leak detector.

Hierarchy

Overview

Methods

Public constructor Create;
Public destructor Destroy; override;
Public function LoadImage_IncReference(const FileName: string): TImage;
Public procedure LoadImage_DecReference(var Image: TImage);

Description

Methods

Public constructor Create;
 
Public destructor Destroy; override;
 
Public function LoadImage_IncReference(const FileName: string): TImage;
 
Public procedure LoadImage_DecReference(var Image: TImage);
 

Generated by PasDoc 0.10.0 on 2008-02-25 00:00:32