summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorAlexander Golubev <fatzer2@gmail.com>2024-03-19 11:30:50 +0300
committerMichele Calgaro <michele.calgaro@yahoo.it>2024-03-22 09:57:01 +0900
commit32f97849285326896fc6d8cf93b0e8c686804bca (patch)
treef02aff3bec22f622ce724ef70d30d9ca3bd19302 /examples
parent4ab92f6b7924b3a24dd3146cfd349d45fe63c995 (diff)
downloadtqt3-32f97849285326896fc6d8cf93b0e8c686804bca.tar.gz
tqt3-32f97849285326896fc6d8cf93b0e8c686804bca.zip
examples/canvas: fix some memory leaks
Signed-off-by: Alexander Golubev <fatzer2@gmail.com> (cherry picked from commit ee63474739f0170485d50711944a430dad98cc91)
Diffstat (limited to 'examples')
-rw-r--r--examples/canvas/canvas.cpp30
-rw-r--r--examples/canvas/canvas.h1
2 files changed, 22 insertions, 9 deletions
diff --git a/examples/canvas/canvas.cpp b/examples/canvas/canvas.cpp
index 3e3e4cd06..bd6589490 100644
--- a/examples/canvas/canvas.cpp
+++ b/examples/canvas/canvas.cpp
@@ -202,17 +202,26 @@ void FigureEditor::contentsMouseMoveEvent(TQMouseEvent* e)
}
}
-
+static uint bouncyLogoCount = 0;
+static TQCanvasPixmapArray *logoarr = 0;
BouncyLogo::BouncyLogo(TQCanvas* canvas) :
TQCanvasSprite(0,canvas)
{
- static TQCanvasPixmapArray logo("qt-trans.xpm");
- setSequence(&logo);
+ if ( !logoarr ) {
+ logoarr = new TQCanvasPixmapArray("qt-trans.xpm");
+ }
+ bouncyLogoCount++;
+ setSequence(logoarr);
setAnimated(TRUE);
initPos();
}
+BouncyLogo::~BouncyLogo()
+{
+ --bouncyLogoCount;
+}
+
const int logo_rtti = 1234;
@@ -301,9 +310,10 @@ void BouncyLogo::advance(int stage)
}
}
+// Some objects to cache among different views
static uint mainCount = 0;
-static TQImage *butterflyimg;
-static TQImage *logoimg;
+static TQImage *butterflyimg = 0;
+static TQImage *logoimg = 0;
Main::Main(TQCanvas& c, TQWidget* parent, const char* name, WFlags f) :
TQMainWindow(parent,name,f),
@@ -368,6 +378,8 @@ Main::Main(TQCanvas& c, TQWidget* parent, const char* name, WFlags f) :
printer = 0;
+ mainCount++;
+
init();
}
@@ -378,10 +390,6 @@ void Main::init()
static int r=24;
srand(++r);
- mainCount++;
- butterflyimg = 0;
- logoimg = 0;
-
int i;
for ( i=0; i<canvas.width() / 56; i++) {
addButterfly();
@@ -402,6 +410,10 @@ Main::~Main()
butterflyimg = 0;
delete[] logoimg;
logoimg = 0;
+ if ( bouncyLogoCount == 0 ) {
+ delete logoarr;
+ logoarr = 0;
+ }
}
}
diff --git a/examples/canvas/canvas.h b/examples/canvas/canvas.h
index 5bbb50883..20e1cc95c 100644
--- a/examples/canvas/canvas.h
+++ b/examples/canvas/canvas.h
@@ -11,6 +11,7 @@ class BouncyLogo : public TQCanvasSprite {
void initSpeed();
public:
BouncyLogo(TQCanvas*);
+ ~BouncyLogo();
void advance(int);
int rtti() const;
};