On Nov 29, 2003, at 11:46 PM, Charles K. Clarkson wrote: [..]
    I joined this thread late, forgive me if this
has been answered. Is there a module or a programmatic
method to ensuring that there are no references left?
[..]

p0: If you want to review a thread on the beginner's
mailing list, one way is to go to:
<http://nntp.x.perl.org/group/perl.beginners>

{ which can help you, if you have, as I have done,
forgotten a specific reference from email, and need
to go back and ask 'oh which module did John Reference...' }

p1: I'm not sure that I 'get' your question about
a module or a programmatic method - but what we
were playing with was

use Devel::Peek;

one of the many interesting modules for helping
coders play around with 'so what REALLLY did that do'.
{ buy the 3rd Edition, READ EVERY PAGE, then traverse
all of the references in the perltoc! }

Like the Benchmark module - some of the ones we did
last time around that I kept are at:
<http://www.wetware.com/drieux/pbl/Other/BenchMarks/>
these are tools for the 'development' side of the game
and not really 'production tricks'.

<sideBar>{
thank you to whom ever was so silly as to teach me
        'just google it drieux, that would be
                FOO + site:wetware.com ....'
Memory Leaks in Primates are such, ugly things, but
at least if one has an active mechanism that can chase
what was written down, one can find it again. I think
this is another variation on 'horder syndrome'...
}</sideBar>

p2: Which brings us to the core problem

        How do I prevent myself from writing code
                that will leak memory by leaving tid bits that
                        have a reference count greater than zero but
                                in such a way that the perl will not be able to
                                        find them and toss the memory onto the heap 
for reuse.

well that starts with chanting

I will not write bad code!

then chant

Reduce, Reuse, Recycle!

and adopting the various basic strategies about how
one goes about looking at a problem and rendering it
first as an algorithm that makes sense, and then correctly
implementing that algorithm in the coding language one chooses.

IF one does not need a complex data Structure,
        Then Just Say NO!

If on the other hand the problem says that the data structure
has a requirement to be complex then chant the old school tie maxim

        Malloc from the Top
        Free From the Bottom

and whip out some sort of 'initializer' function that
will if the thingiePoo is non-Null start out by calling
the tree_traverser() that will decend the complex data
structure making sure that the leaf nodes can be tossed safely
till one gets to the top of the tree and it all be gone bye-bye!
At which point the initializer() will start hanging good stuff.
{ some cultists use the terms 'constructors' and 'destructors'
find the language you feel safest with }

{ note: talking to the Problem is always good! Ask the Problem
how it feels about data modelling, where has it been, where
is it going. If you are nice to the Problem, it will be nice to you.
Take the Problem out for a dinner and a movie, get in touch
with it's inner feelings and issues. Find out what it knows
about itself Makes coding so much easier. }

If that complex data structure needs to be 'accessed' at
various bits and bobs 'inside it' then resolve who will
be responsible for 'accessing' the data structure - does
this part of the design say:

Must have Accessor To Foo In Bar At Baz

eg
        $bar->get_foo($baz);

and should that

        a. pass out the reference - hence incrementing the ref count -
                and possibly allowing some Primate to ABUSE YOUR CODE!
        b. COPY OUT the data - hence reconstructing the data into new memory
                and handing the reference to New Memory back to the caller.

{ note: there is NO WAY to prevent Code Abuse! Primates DO IT!
and as long as they keep hiring primates to Code there will
be code at Risk! Just Say NO! To Code Abuse!!! Yes, Yes, Yes,
I know that Carp et al can help POINT back to the Primate's
Keyboard Pounding as the Source of the Dark Evil - but trust me
PRIMATES SMELL FUNNY and can do bad things with CODE!!! }

When you think you have a coding solution, then comes the fun!
Prooving that it is a 'minimal spanning set' - see what you can
just TOSS OUT until you are sure in your soul that it is as
tight and maintainable as is humanly possible. { if you need
to learn that only God is Perfect, take up golf. Or in this
case try Perl Golf. }

If YOU have cool bits that are Cool, learn to put them in
appropriate Perl Modules, so that you can just re-use them
when ever you need some

$bar->get_foo($baz);

Never be afraid to join a Coder Therapy Group, and to share
with the Group your 'issues' - what is the worst that happens?
They say:

        Your mother dresses you funny
                and you code smells toooooo!!!!

They may not be able to help you with the former, but along
the way the later issue can be, well cleaned up.

p3: If all else fails, never be afraid to take a core DUMP
of your code, print it out in some lovely long stream of
Hex, whip out your colour markers and annotate your way
through it and if you can not find any danging references
then you have at least proven that in that instance of
runtime there was nothing Obviously Bad about it.
{ do not try this at home Boys and Girls! These are
Paid Professionals, and we can tell 'the beautiful minds'
from people merely making arcane markings... }

HTH.

ciao
drieux

---


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to