[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
- <!--x-content-type: text/plain -->
- <!--x-date: Fri Sep 24 22:45:54 2004 -->
- <!--x-from-r13: owbea ng fppf.fjneguzber.rqh (Pwbea Rvggzre-Dbpur) -->
- <!--x-message-id: [email protected]-a-geek.com -->
- <!--x-reference: Pine.LNX.4.44.0409241928230.13308-[email protected] -->
- <!--x-reference: [email protected] --> "http://www.w3.org/TR/html4/loose.dtd">
- <!--x-subject: [ale] C++ Debuggery and the Path of Destruction -->
- <li><em>date</em>: Fri Sep 24 22:45:54 2004</li>
- <li><em>from</em>: bjorn at sccs.swarthmore.edu (Bjorn Dittmer-Roche)</li>
- <li><em>in-reply-to</em>: <<a href="msg00844.html">[email protected]</a>></li>
- <li><em>references</em>: <[email protected]> <<a href="msg00844.html">[email protected]</a>></li>
- <li><em>subject</em>: [ale] C++ Debuggery and the Path of Destruction</li>
> On Friday 24 September 2004 08:41 pm, John Mills wrote:
>> ALErs -
>>
>
>> Naturally, I got a bit too clever
>
> It's almost certainly going to be easier to rewrite it as something less
> clever, but hey, where's the fun in that?
>
> ;-)
>
>> Any suggestions how to track this self-administered wedgie down?
>
> Any chance of posting some code?
>
> I finally gave up on getting memory management right the first (second,
> nth...) time and started populating my code with debug statements to the
> effect of:
>
> __FILE__::__LINE__ is now creating a __WHATEVER__, address 0xabcddcab
> __FILE__::__LINE__ is now deleting a __WHATEVER__, address 0xabcddcab
This is handy. My trick is for each object that has a malloc or new, that
object is responsible for deleting/free ing the data as well. Paired with
a counter to keep track of mallocs in each object is handy and I tend to
catch memory leaks fast:
for example:
constructor()
{
malloc _whatever_ ;
++malloccount;
}
method1()
{
malloc _another_whatever;
++malloccount;
}
method2()
{
free _anbother_whatever;
--malloccount;
}
destructor()
{
free _whatever_ ;
--malloccount;
if( malloccount < 0 )
throw FatalException( "Double free!" );
else if( malloccount > 0 )
throw FatalException( "Memory Leak!" );
}
My pseudo-code here is awful, but you get the idea....
bjorn
-------------------
Bjorn Dittmer-Roche
XO Audio LLC
<a rel="nofollow" href="http://www.xowave.com">http://www.xowave.com</a>
<a rel="nofollow" href="http://www.xoaudio.com">http://www.xoaudio.com</a>
</pre>
<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<hr>
<ul><li><strong>Follow-Ups</strong>:
<ul>
<li><strong><a name="00849" href="msg00849.html">[ale] C++ Debuggery and the Path of Destruction</a></strong>
<ul><li><em>From:</em> esoteric at 3times25.net (Geoffrey)</li></ul></li>
</ul></li></ul>
<!--X-Follow-Ups-End-->
<!--X-References-->
<ul><li><strong>References</strong>:
<ul>
<li><strong><a name="00843" href="msg00843.html">[ale] C++ Debuggery and the Path of Destruction</a></strong>
<ul><li><em>From:</em> johnmills at speakeasy.net (John Mills)</li></ul></li>
<li><strong><a name="00844" href="msg00844.html">[ale] C++ Debuggery and the Path of Destruction</a></strong>
<ul><li><em>From:</em> rountree at cs.uga.edu (Barry Rountree)</li></ul></li>
</ul></li></ul>
<!--X-References-End-->
<!--X-BotPNI-->
<ul>
<li>Prev by Date:
<strong><a href="msg00846.html">[ale] Linux Mail Server Recomendations</a></strong>
</li>
<li>Next by Date:
<strong><a href="msg00848.html">[ale] C++ Debuggery and the Path of Destruction</a></strong>
</li>
<li>Previous by thread:
<strong><a href="msg00851.html">[ale] C++ Debuggery and the Path of Destruction</a></strong>
</li>
<li>Next by thread:
<strong><a href="msg00849.html">[ale] C++ Debuggery and the Path of Destruction</a></strong>
</li>
<li>Index(es):
<ul>
<li><a href="maillist.html#00847"><strong>Date</strong></a></li>
<li><a href="threads.html#00847"><strong>Thread</strong></a></li>
</ul>
</li>
</ul>
<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
</body>
</html>