[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]



> 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>