From 791d861ab704103f37e2059eaa2829c404531e44 Mon Sep 17 00:00:00 2001 From: Stefan Sayer Date: Thu, 12 Mar 2009 12:53:30 +0000 Subject: [PATCH] fixing memory leak in example git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@1313 8eb893ce-cfd4-0310-b710-fb5ebe64c474 --- apps/examples/tutorial/myjukebox/MyJukebox.cpp | 6 ++++++ apps/examples/tutorial/myjukebox/MyJukebox.h | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/apps/examples/tutorial/myjukebox/MyJukebox.cpp b/apps/examples/tutorial/myjukebox/MyJukebox.cpp index 3129f106..143d02ac 100644 --- a/apps/examples/tutorial/myjukebox/MyJukebox.cpp +++ b/apps/examples/tutorial/myjukebox/MyJukebox.cpp @@ -45,6 +45,10 @@ MyJukeboxDialog::~MyJukeboxDialog() { // clean playlist items playlist.close(false); + // clean used AmAudioFile objects + for (vector::iterator it= + used_audio_files.begin(); it != used_audio_files.end();it++) + delete *it; } void MyJukeboxDialog::onSessionStart(const AmSipRequest& req) @@ -67,6 +71,8 @@ void MyJukeboxDialog::onDtmf(int event, int duration) { } AmPlaylistItem* item = new AmPlaylistItem(wav_file, NULL); playlist.addToPlaylist(item); + // for garbage collection later + used_audio_files.push_back(wav_file); } void MyJukeboxDialog::process(AmEvent* ev) diff --git a/apps/examples/tutorial/myjukebox/MyJukebox.h b/apps/examples/tutorial/myjukebox/MyJukebox.h index 0c233e14..ad6e99c2 100644 --- a/apps/examples/tutorial/myjukebox/MyJukebox.h +++ b/apps/examples/tutorial/myjukebox/MyJukebox.h @@ -3,10 +3,14 @@ #include "AmSession.h" #include "AmPlaylist.h" +#include "AmAudioFile.h" #include using std::string; +#include +using std::vector; + class MyJukeboxFactory: public AmSessionFactory { public: @@ -22,6 +26,8 @@ class MyJukeboxDialog : public AmSession { AmPlaylist playlist; + vector used_audio_files; + public: MyJukeboxDialog(); ~MyJukeboxDialog();