summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorAlexander Golubev <fatzer2@gmail.com>2024-03-19 11:30:50 +0300
committerTDE Gitea <gitea@mirror.git.trinitydesktop.org>2024-03-22 00:55:35 +0000
commitee63474739f0170485d50711944a430dad98cc91 (patch)
treec7a0b61745cd0cea9b1685d7e62daa3cfe0ed5fa /examples
parent4bcca712ef79d897fe3cc523b9c13f69fcf5d34d (diff)
downloadtqt3-ee63474739f0170485d50711944a430dad98cc91.tar.gz
tqt3-ee63474739f0170485d50711944a430dad98cc91.zip
examples/canvas: fix some memory leaks
Signed-off-by: Alexander Golubev <fatzer2@gmail.com>
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;
};