develooper Front page | perl.perl5.porters | Postings from August 2010

The need for perl_destruct()

Thread Next
Reini Urban
August 2, 2010 13:47
The need for perl_destruct()
Message ID:
I'm doing quite fine with breaking a new perl speed record.
exit() is free'ing my malloc'ed memory just fine, and I'm doing no embedding.

int fast_perl_destruct( PerlInterpreter *my_perl ) {
    VOL signed char destruct_level;  /* see possible values in intrpvar.h */
    HV *hv;

    assert(PL_scopestack_ix == 1);

    /* wait for all pseudo-forked children to finish */

    destruct_level = PL_perl_destruct_level;
	const char * const s = PerlEnv_getenv("PERL_DESTRUCT_LEVEL");
	if (s) {
            const int i = atoi(s);
	    if (destruct_level < i)
		destruct_level = i;

    if (PL_exit_flags & PERL_EXIT_DESTRUCT_END) {
        int x = 0;

        if (PL_endav && !PL_minus_c)
            call_list(PL_scopestack_ix, PL_endav);
    assert(PL_scopestack_ix == 0);

    /* Need to flush since END blocks can produce output */

    if (CALL_FPTR(PL_threadhook)(aTHX)) {
        /* Threads hook has vetoed further cleanup */
	PL_veto_cleanup = TRUE;
        return STATUS_EXIT;

Missing is op_free (with attached sv_free), sv_clean_all,
and all the NULL setting of the globals.
So, what is the global destruction really needed for?

calling END blocks - call_list(PL_scopestack_ix, PL_endav)
tearing down threads
tearing down PerlIO, esp. flush (close is not really needed)

What else?
Calling DESTROY hooks is the big remaining feature, which is really required.
I'm thinking of a fast way to call all remaining DESTROY methods, but this
should be it. Or did I miss something else?

I don't care for freeing ops and svs, and esp. do not care for the
long winding road finding all. And in the B::C compiler most of those
are initialized static, so they don't need to be freed at all.

Note that long-running server processes make no difference. They never
reclaim memory,
only at then end of the long-running process. So it will grow and
grow, and "leaks" at the
end will just be reclaimed by the OS.
Just embedding is affected. I don't care for embedding.
Reini Urban

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About