[MTOS-dev] Detecting memory leaks on FCGI environment

Hirotaka Ogawa hirotaka.ogawa at gmail.com
Tue Mar 4 20:10:01 PST 2008


Hi,

I always use the following bootstrap script in order to detect memory
leaks on FCGI environment.

---
#!/usr/bin/perl -w

use strict;
use lib $ENV{MT_HOME} ? "$ENV{MT_HOME}/lib" : 'lib';
use Devel::Leak::Object qw{ GLOBAL_bless };
use MT::Bootstrap;
use MT::App::CMS;
use CGI::Fast;

while (my $cgi = new CGI::Fast) {
    my $app = MT::App::CMS->new(CGIObject => $cgi)
        or die MT::App::CMS->errstr;
    local $SIG{__WARN__} = sub { $app->trace($_[0]) };
    MT->set_instance($app);
    $app->init_request(CGIObject => $cgi);
    $app->run;
    Devel::Leak::Object::status();
}
---

This script dumps the counts of live (or leaked) objects at every
requests.  Therefore, we can detect leaks if their counts grow bigger.

This is the only method that I've employed, but clearly it's not
perfect.  For example, when there's an array owned by MT::App::CMS and
it grows bigger and bigger as requests, we cannot detect leaks by this
script.

I would appreciate it if you could tell more sophisticated methods.

-- 
Hirotaka Ogawa makes no sense.
http://as-is.net/blog/


More information about the MTOS-dev mailing list