in reply to Dereferencing question

How are you using @a outside of the object?

Generally, cleaning this up would be done by either the implicit or a custom DESTROY(). However, if you are returning the ref to an outside program, then (correct me if I'm wrong) Perl can't destroy it, because there are still references to it. AFAIK, Perl won't allow 'dangling pointers', but I've never tested this in your context.

For that matter, I don't even know if your cleanUp() could wreck the reference that the package gave out, as it doesn't even belong to the object of the package. Perhaps someone could clarify this.

Furthermore, hopefully your variables are named as such for example only, because I've been smacked around a few times for using @A and 'sub A' etc ;)

Steve

Replies are listed 'Best First'.
Re^2: Dereferencing question
by bob_dobalina (Sexton) on Sep 02, 2009 at 14:18 UTC
    Here's some example usage; the references shouldn't in "doSomething" go away when you go out of it's (sub doSomething)'s scope?
    use MyObject; # -------------------------------- # main.pl # -------------------------------- my $object = undef; $object = new MyObject; $object->fillIt(); doSomething($object->A); sub doSomething { my $arrayReference = shift; foreach my $hashReference (@$arrayReference) { # do something } } $object->cleanUp(); exit 0;
    so you are saying:
    @a = ();
    will clean up all the hashreferences in @a?