Changed the singleton implementation in GraphicsCache, the former version

leaked, in the sense that it was not deallocated at program end.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1640 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Baruch Even 2001-02-28 11:32:10 +00:00
parent 7edc50d28d
commit 95aa44f550
5 changed files with 19 additions and 19 deletions

View File

@ -1,3 +1,10 @@
2001-02-28 Baruch Even <baruch@ev-en.org>
* GraphicsCache.h:
* GraphicsCache.C: Changed the singleton pattern implementation, the
former version "leaked" in the sense that it was not deallocated at
program end.
2001-02-20 Baruch Even <baruch@ev-en.org>
* GraphicsCache.C: Changed to use shared_ptr<GraphicsCacheItem>

View File

@ -20,17 +20,10 @@
#include "support/LAssert.h"
GraphicsCache * GraphicsCache::singleton = 0;
GraphicsCache *
GraphicsCache &
GraphicsCache::getInstance()
{
if (!singleton) {
singleton = new GraphicsCache;
Assert(singleton != 0);
}
static GraphicsCache singleton;
return singleton;
}
@ -39,8 +32,6 @@ GraphicsCache::~GraphicsCache()
{
// The map elements should have already been eliminated.
Assert(cache.empty());
delete singleton;
}

View File

@ -34,7 +34,9 @@ class GraphicsCacheItem;
class GraphicsCache : public noncopyable {
public:
/// Get the instance of the class.
static GraphicsCache * getInstance();
static GraphicsCache & getInstance();
/// Public destructor due to compiler warnings.
~GraphicsCache();
typedef boost::shared_ptr<GraphicsCacheItem> shared_ptr_item;
@ -48,11 +50,6 @@ private:
/// Private c-tor so we can control how many objects are instantiated.
GraphicsCache() {}
/// Private d-tor so that no-one will destroy us.
~GraphicsCache();
/// Holder of the single instance of the class.
static GraphicsCache * singleton;
///
typedef std::map<string, shared_ptr_item> CacheType;
///

View File

@ -1,3 +1,8 @@
2001-02-28 Baruch Even <baruch@ev-en.org>
* insetgraphics.C (updateInset): Changed due to the change in
GraphicsCache.
2001-02-26 Juergen Vigna <jug@sad.it>
* insettext.C (SetFont): Set Undo only if we have selection (as it is

View File

@ -575,13 +575,13 @@ void InsetGraphics::Validate(LaTeXFeatures & features) const
// dialog.
void InsetGraphics::updateInset() const
{
GraphicsCache * gc = GraphicsCache::getInstance();
GraphicsCache & gc = GraphicsCache::getInstance();
boost::shared_ptr<GraphicsCacheItem> temp(0);
// We do it this way so that in the face of some error, we will still
// be in a valid state.
if (!params.filename.empty()) {
temp = gc->addFile(params.filename);
temp = gc.addFile(params.filename);
}
// Mark the image as unloaded so that it gets updated.