From 95aa44f5507d95feef8b3b8e0101bf550a0f79eb Mon Sep 17 00:00:00 2001 From: Baruch Even Date: Wed, 28 Feb 2001 11:32:10 +0000 Subject: [PATCH] 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 --- src/graphics/ChangeLog | 7 +++++++ src/graphics/GraphicsCache.C | 13 ++----------- src/graphics/GraphicsCache.h | 9 +++------ src/insets/ChangeLog | 5 +++++ src/insets/insetgraphics.C | 4 ++-- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/graphics/ChangeLog b/src/graphics/ChangeLog index 9cedf2bc33..16696974ea 100644 --- a/src/graphics/ChangeLog +++ b/src/graphics/ChangeLog @@ -1,3 +1,10 @@ +2001-02-28 Baruch Even + + * 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 * GraphicsCache.C: Changed to use shared_ptr diff --git a/src/graphics/GraphicsCache.C b/src/graphics/GraphicsCache.C index a2bed25973..cda36db9fc 100644 --- a/src/graphics/GraphicsCache.C +++ b/src/graphics/GraphicsCache.C @@ -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; } diff --git a/src/graphics/GraphicsCache.h b/src/graphics/GraphicsCache.h index 3f28d385cc..240157992b 100644 --- a/src/graphics/GraphicsCache.h +++ b/src/graphics/GraphicsCache.h @@ -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 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 CacheType; /// diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 57f3a521c6..e31a6069ed 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,8 @@ +2001-02-28 Baruch Even + + * insetgraphics.C (updateInset): Changed due to the change in + GraphicsCache. + 2001-02-26 Juergen Vigna * insettext.C (SetFont): Set Undo only if we have selection (as it is diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index 5ea6f7c085..cb77d32871 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -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 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. -- 2.39.5