From: Paul Davis Date: Sat, 28 Nov 2009 00:49:04 +0000 (+0000) Subject: tracing and small fixes to improve object destruction pathways X-Git-Tag: 3.0-alpha5~2723 X-Git-Url: https://main.carlh.net/gitweb/?p=ardour.git;a=commitdiff_plain;h=51693a3a5835a7c2deb16242d14d73fbb7881382 tracing and small fixes to improve object destruction pathways git-svn-id: svn://localhost/ardour2/branches/3.0@6195 d708f5d6-7413-0410-9779-e7cbd77b26cf --- diff --git a/libs/ardour/audio_diskstream.cc b/libs/ardour/audio_diskstream.cc index faa4684745..7ef971642d 100644 --- a/libs/ardour/audio_diskstream.cc +++ b/libs/ardour/audio_diskstream.cc @@ -49,6 +49,7 @@ #include "ardour/butler.h" #include "ardour/configuration.h" #include "ardour/cycle_timer.h" +#include "ardour/debug.h" #include "ardour/io.h" #include "ardour/playlist_factory.h" #include "ardour/region_factory.h" @@ -122,7 +123,7 @@ AudioDiskstream::init (Diskstream::Flag f) AudioDiskstream::~AudioDiskstream () { - cerr << "AD going away\n"; + DEBUG_TRACE (DEBUG::Destruction, string_compose ("Audio Diskstream %1 destructor\n", _name)); notify_callbacks (); diff --git a/libs/ardour/audio_playlist.cc b/libs/ardour/audio_playlist.cc index eb4913e727..30479cf65b 100644 --- a/libs/ardour/audio_playlist.cc +++ b/libs/ardour/audio_playlist.cc @@ -351,7 +351,7 @@ AudioPlaylist::check_dependents (boost::shared_ptr r, bool norefresh) boost::shared_ptr top; boost::shared_ptr bottom; boost::shared_ptr xfade; - RegionList* touched_regions; + RegionList* touched_regions = 0; if (in_set_state || in_partition) { return; @@ -401,6 +401,8 @@ AudioPlaylist::check_dependents (boost::shared_ptr r, bool norefresh) OverlapType c = top->coverage (bottom->position(), bottom->last_frame()); + delete touched_regions; + try { switch (c) { case OverlapNone: @@ -509,6 +511,8 @@ AudioPlaylist::check_dependents (boost::shared_ptr r, bool norefresh) } } + + delete touched_regions; } void diff --git a/libs/ardour/audiofilesource.cc b/libs/ardour/audiofilesource.cc index e9eb3641da..f2f09b71fc 100644 --- a/libs/ardour/audiofilesource.cc +++ b/libs/ardour/audiofilesource.cc @@ -45,6 +45,7 @@ #include #include "ardour/audiofilesource.h" +#include "ardour/debug.h" #include "ardour/sndfile_helpers.h" #include "ardour/sndfilesource.h" #include "ardour/session.h" @@ -99,7 +100,6 @@ AudioFileSource::AudioFileSource (Session& s, const ustring& path, bool embedded if (init (path, true)) { throw failed_constructor (); } - cerr << "AFS1 created, " << path << endl; } /** Constructor used for new internal-to-session files. */ @@ -114,7 +114,6 @@ AudioFileSource::AudioFileSource (Session& s, const ustring& path, bool embedded if (init (path, false)) { throw failed_constructor (); } - cerr << "AFS2 created, " << path << endl; } /** Constructor used for existing internal-to-session files. File must exist. */ @@ -130,14 +129,12 @@ AudioFileSource::AudioFileSource (Session& s, const XMLNode& node, bool must_exi if (init (_name, must_exist)) { throw failed_constructor (); } - cerr << "AFS3 created, " << path() << endl; } AudioFileSource::~AudioFileSource () { - cerr << "AFS " << _name << " destructor, path = " << path() << endl; + DEBUG_TRACE (DEBUG::Destruction, string_compose ("AudioFileSource destructor %1, removable? %2\n", _path, removable())); if (removable()) { - cerr << "\tremoving file\n"; unlink (_path.c_str()); unlink (peakpath.c_str()); } diff --git a/libs/ardour/diskstream.cc b/libs/ardour/diskstream.cc index b6cc9d6a04..e2dfc27100 100644 --- a/libs/ardour/diskstream.cc +++ b/libs/ardour/diskstream.cc @@ -129,9 +129,11 @@ Diskstream::init (Flag f) Diskstream::~Diskstream () { - if (_playlist) - _playlist->release (); DEBUG_TRACE (DEBUG::Destruction, string_compose ("Diskstream %1 deleted\n", _name)); + + if (_playlist) { + _playlist->release (); + } } void diff --git a/libs/ardour/playlist.cc b/libs/ardour/playlist.cc index f57093ea40..aa41bf65d1 100644 --- a/libs/ardour/playlist.cc +++ b/libs/ardour/playlist.cc @@ -32,6 +32,7 @@ #include "pbd/xml++.h" #include "pbd/stacktrace.h" +#include "ardour/debug.h" #include "ardour/playlist.h" #include "ardour/session.h" #include "ardour/region.h" @@ -270,6 +271,7 @@ Playlist::init (bool hide) Playlist::~Playlist () { + DEBUG_TRACE (DEBUG::Destruction, string_compose ("Playlist %1 destructor\n", _name)); { RegionLock rl (this); diff --git a/libs/ardour/region.cc b/libs/ardour/region.cc index c59a5bb562..cbfd9a9b33 100644 --- a/libs/ardour/region.cc +++ b/libs/ardour/region.cc @@ -339,9 +339,9 @@ Region::Region (boost::shared_ptr src, const XMLNode& node) Region::~Region () { + DEBUG_TRACE (DEBUG::Destruction, string_compose ("Region %1 destructor @ %2\n", _name, this)); notify_callbacks (); GoingAway (); /* EMIT SIGNAL */ - DEBUG_TRACE (DEBUG::Destruction, string_compose ("Region %1 deleted\n", _name)); } void diff --git a/libs/ardour/region_factory.cc b/libs/ardour/region_factory.cc index 8b2d30d511..91cc2dbe2a 100644 --- a/libs/ardour/region_factory.cc +++ b/libs/ardour/region_factory.cc @@ -18,6 +18,7 @@ */ #include "pbd/error.h" +#include "pbd/boost_debug.h" #include "ardour/session.h" @@ -45,6 +46,7 @@ RegionFactory::create (boost::shared_ptr region, nframes_t start, if ((other_a = boost::dynamic_pointer_cast(region)) != 0) { AudioRegion* ar = new AudioRegion (other_a, start, length, name, layer, flags); + boost_debug_shared_ptr_mark_interesting (ar, typeid (ar).name()); boost::shared_ptr arp (ar); boost::shared_ptr ret (boost::static_pointer_cast (arp)); ret->unlock_property_changes (); @@ -76,7 +78,9 @@ RegionFactory::create (boost::shared_ptr region) boost::shared_ptr mr; if ((ar = boost::dynamic_pointer_cast(region)) != 0) { - boost::shared_ptr ret (new AudioRegion (ar)); + AudioRegion* arn = new AudioRegion (ar); + boost_debug_shared_ptr_mark_interesting (arn, typeid (arn).name()); + boost::shared_ptr ret (arn); ret->unlock_property_changes (); /* pure copy constructor - no CheckNewRegion emitted */ return ret; @@ -114,6 +118,7 @@ RegionFactory::create (boost::shared_ptr region, const SourceList& srcs, if ((other = boost::dynamic_pointer_cast(region)) != 0) { AudioRegion* ar = new AudioRegion (other, srcs, srcs.front()->length(srcs.front()->timeline_position()), name, layer, flags); + boost_debug_shared_ptr_mark_interesting (ar, typeid (ar).name()); boost::shared_ptr arp (ar); boost::shared_ptr ret (boost::static_pointer_cast (arp)); ret->unlock_property_changes (); @@ -152,6 +157,7 @@ RegionFactory::create (const SourceList& srcs, nframes_t start, nframes_t length if (srcs[0]->type() == DataType::AUDIO) { AudioRegion* ar = new AudioRegion (srcs, start, length, name, layer, flags); + boost_debug_shared_ptr_mark_interesting (ar, typeid (ar).name()); boost::shared_ptr arp (ar); boost::shared_ptr ret (boost::static_pointer_cast (arp)); ret->unlock_property_changes (); @@ -184,7 +190,9 @@ RegionFactory::create (SourceList& srcs, const XMLNode& node) } if (srcs[0]->type() == DataType::AUDIO) { - boost::shared_ptr ret (new AudioRegion (srcs, node)); + AudioRegion* ar = new AudioRegion (srcs, node); + boost_debug_shared_ptr_mark_interesting (ar, typeid (ar).name()); + boost::shared_ptr ret (ar); ret->unlock_property_changes (); CheckNewRegion (ret); return ret; @@ -205,7 +213,9 @@ RegionFactory::create (boost::shared_ptr src, nframes_t start, nframes_t boost::shared_ptr ms; if ((as = boost::dynamic_pointer_cast(src)) != 0) { - boost::shared_ptr ret (new AudioRegion (as, start, length, name, layer, flags)); + AudioRegion* ar = new AudioRegion (as, start, length, name, layer, flags); + boost_debug_shared_ptr_mark_interesting (ar, typeid (ar).name()); + boost::shared_ptr ret (ar); ret->unlock_property_changes (); if (announce) { CheckNewRegion (ret); diff --git a/libs/ardour/route.cc b/libs/ardour/route.cc index 912e80c0ea..1b8dfaec46 100644 --- a/libs/ardour/route.cc +++ b/libs/ardour/route.cc @@ -161,6 +161,7 @@ Route::init () Route::~Route () { + DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name)); Metering::disconnect (_meter_connection); /* don't use clear_processors here, as it depends on the session which may @@ -170,6 +171,7 @@ Route::~Route () for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) { (*i)->drop_references (); } + _processors.clear (); } diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 67f41a906f..f7dfd2111d 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -400,7 +400,7 @@ Session::destroy () i = tmp; } - DEBUG_TRACE (DEBUG::Destruction, "delete playlists\n"); + DEBUG_TRACE (DEBUG::Destruction, "delete used playlists\n"); for (PlaylistList::iterator i = playlists.begin(); i != playlists.end(); ) { PlaylistList::iterator tmp; @@ -409,11 +409,12 @@ Session::destroy () DEBUG_TRACE(DEBUG::Destruction, string_compose ("Dropping for used playlist %1 ; pre-ref = %2\n", (*i)->name(), (*i).use_count())); (*i)->drop_references (); - DEBUG_TRACE(DEBUG::Destruction, string_compose ("post-ref = %1\n", (*i).use_count())); + i = tmp; } + DEBUG_TRACE (DEBUG::Destruction, "delete unused playlists\n"); for (PlaylistList::iterator i = unused_playlists.begin(); i != unused_playlists.end(); ) { PlaylistList::iterator tmp; @@ -422,7 +423,6 @@ Session::destroy () DEBUG_TRACE(DEBUG::Destruction, string_compose ("Dropping for unused playlist %1 ; pre-ref = %2\n", (*i)->name(), (*i).use_count())); (*i)->drop_references (); - DEBUG_TRACE(DEBUG::Destruction, string_compose ("post-ref = %2\n", (*i).use_count())); i = tmp; } @@ -437,24 +437,28 @@ Session::destroy () tmp = i; ++tmp; - DEBUG_TRACE(DEBUG::Destruction, string_compose ("Dropping for region %1 ; pre-ref = %2\n", i->second->name(), i->second.use_count())); + DEBUG_TRACE(DEBUG::Destruction, string_compose ("Dropping for region %1 (%2); pre-ref = %2\n", i->second->name(), i->second.get(), i->second.use_count())); i->second->drop_references (); - DEBUG_TRACE(DEBUG::Destruction, string_compose ("\tpost-ref%2\n", i->second.use_count())); - + DEBUG_TRACE(DEBUG::Destruction, string_compose ("region post ref = %1\n", i->second.use_count())); i = tmp; } regions.clear (); DEBUG_TRACE (DEBUG::Destruction, "delete routes\n"); + + /* reset these three references to special routes before we do the usual route delete thing */ + + auditioner.reset (); + _master_out.reset (); + _control_out.reset (); + { RCUWriter writer (routes); boost::shared_ptr r = writer.get_copy (); for (RouteList::iterator i = r->begin(); i != r->end(); ++i) { DEBUG_TRACE(DEBUG::Destruction, string_compose ("Dropping for route %1 ; pre-ref = %2\n", (*i)->name(), (*i).use_count())); (*i)->drop_references (); - DEBUG_TRACE(DEBUG::Destruction, string_compose ("post-ref = %1\n", (*i).use_count())); - debug_pointers.push_back ((*i).get()); } r->clear (); /* writer goes out of scope and updates master */ @@ -468,7 +472,6 @@ Session::destroy () for (DiskstreamList::iterator i = dsl->begin(); i != dsl->end(); ++i) { DEBUG_TRACE(DEBUG::Destruction, string_compose ("Dropping for diskstream %1 ; pre-ref = %2\n", (*i)->name(), (*i).use_count())); (*i)->drop_references (); - DEBUG_TRACE(DEBUG::Destruction, string_compose ("post-ref = %1\n", (*i).use_count())); } dsl->clear (); } @@ -483,13 +486,12 @@ Session::destroy () DEBUG_TRACE(DEBUG::Destruction, string_compose ("Dropping for source %1 ; pre-ref = %2\n", i->second->path(), i->second.use_count())); i->second->drop_references (); - DEBUG_TRACE(DEBUG::Destruction, string_compose ("\tpost-ref%1\n", i->second.use_count())); i = tmp; } - cerr << "Pre source clear, we have " << sources.size() << endl; + sources.clear (); - cerr << "Post source clear, we have " << sources.size() << endl; + DEBUG_TRACE (DEBUG::Destruction, "delete route groups\n"); for (list::iterator i = _route_groups.begin(); i != _route_groups.end(); ++i) { @@ -501,6 +503,8 @@ Session::destroy () delete mmc; boost_debug_list_ptrs (); + + DEBUG_TRACE (DEBUG::Destruction, "Session::destroy() done\n"); } void @@ -1520,8 +1524,6 @@ Session::resort_routes_using (shared_ptr r) for (i = r->begin(); i != r->end(); ++i) { - cerr << "\n\n\n CLEAR FED BY for " << (*i)->name() << endl; - (*i)->fed_by.clear (); for (j = r->begin(); j != r->end(); ++j) { @@ -1785,7 +1787,7 @@ Session::new_audio_track (int input_channels, int output_channels, TrackMode mod try { AudioTrack* at = new AudioTrack (*this, track_name, Route::Flag (0), mode); - boost_debug_shared_ptr_mark_interesting (at, typeid (at).name()); + // boost_debug_shared_ptr_mark_interesting (at, typeid (at).name()); track = boost::shared_ptr(at); if (track->input()->ensure_io (ChanCount(DataType::AUDIO, input_channels), false, this)) { @@ -3722,10 +3724,10 @@ void Session::graph_reordered () { /* don't do this stuff if we are setting up connections - from a set_state() call or creating new tracks. + from a set_state() call or creating new tracks. Ditto for deletion. */ - if (_state_of_the_state & InitialConnecting) { + if (_state_of_the_state & (InitialConnecting|Deletion)) { return; } diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index f53dd7106e..1664b0b9f9 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -1405,7 +1405,7 @@ Session::XMLRouteFactory (const XMLNode& node, int version) if (has_diskstream) { if (type == DataType::AUDIO) { AudioTrack* at = new AudioTrack (*this, node, version); - boost_debug_shared_ptr_mark_interesting (at, typeid (at).name()); + // boost_debug_shared_ptr_mark_interesting (at, typeid (at).name()); boost::shared_ptr ret (at); return ret; } else { diff --git a/libs/ardour/source.cc b/libs/ardour/source.cc index 10b7ead270..790b7f6c3e 100644 --- a/libs/ardour/source.cc +++ b/libs/ardour/source.cc @@ -75,8 +75,8 @@ Source::Source (Session& s, const XMLNode& node) Source::~Source () { + DEBUG_TRACE (DEBUG::Destruction, string_compose ("Source %1 destructor\n", _name)); notify_callbacks (); - DEBUG_TRACE (DEBUG::Destruction, string_compose ("Source %1 deleted\n", _name)); } diff --git a/libs/ardour/track.cc b/libs/ardour/track.cc index ce208769f6..01201d38e7 100644 --- a/libs/ardour/track.cc +++ b/libs/ardour/track.cc @@ -24,6 +24,7 @@ #include "ardour/audioplaylist.h" #include "ardour/audioregion.h" #include "ardour/audiosource.h" +#include "ardour/debug.h" #include "ardour/delivery.h" #include "ardour/diskstream.h" #include "ardour/io_processor.h" @@ -62,6 +63,7 @@ Track::Track (Session& sess, const XMLNode& node, DataType default_type) Track::~Track () { + DEBUG_TRACE (DEBUG::Destruction, string_compose ("track %1 destructor\n", _name)); } void diff --git a/libs/pbd/boost_debug.cc b/libs/pbd/boost_debug.cc index c9487197e1..33e7bb3564 100644 --- a/libs/pbd/boost_debug.cc +++ b/libs/pbd/boost_debug.cc @@ -142,6 +142,7 @@ boost_debug_shared_ptr_mark_interesting (void* ptr, const char* type) Glib::Mutex::Lock guard (the_lock); pair newpair (ptr, type); interesting_pointers.insert (newpair); + // cerr << "Interesting object @ " << ptr << " of type " << type << endl; } void @@ -168,12 +169,13 @@ boost_debug_shared_ptr_destructor (void const *sp, void const *obj, int use_coun if (x != sptrs.end()) { sptrs.erase (x); + // cerr << "Removed sp for " << obj << " @ " << sp << endl; } } + void boost_debug_shared_ptr_constructor (void const *sp, void const *obj, int use_count) { - if (is_interesting_object (obj)) { Glib::Mutex::Lock guard (the_lock); pair newpair; @@ -182,6 +184,7 @@ boost_debug_shared_ptr_constructor (void const *sp, void const *obj, int use_cou newpair.second = new SPDebug (new Backtrace()); sptrs.insert (newpair); + // cerr << "Stored constructor for " << obj << " @ " << sp << endl; } } @@ -189,10 +192,15 @@ void boost_debug_list_ptrs () { Glib::Mutex::Lock guard (the_lock); - for (PointerMap::iterator x = sptrs.begin(); x != sptrs.end(); ++x) { - cerr << "Shared ptr @ " << x->first << " history: " - << *x->second - << endl; + + if (sptrs.empty()) { + cerr << "There are no dangling shared ptrs\n"; + } else { + for (PointerMap::iterator x = sptrs.begin(); x != sptrs.end(); ++x) { + cerr << "Shared ptr @ " << x->first << " history: " + << *x->second + << endl; + } } }