再次感谢诺基亚论坛的 beover1984 提供帮助!

【参考文章】:http://www.symbian.net.cn/blog/post/5.html

声明:虽然上面的【参考文章】标题是 Use HookLogger to trace memroy leak in S60 3rd SDK ,但 S60 第二版也适用!

需要说明的是 EPOCROOT 是在 Windows 系统变量中改的且前后都要有“/”(不是 Windows 下用的“\”)

也可以不用系统变量而直接使用下面的 perl 代码 替换 HookEUSER.pl 的内容 , 并把第53行改为你的 SDK 路径(注意无盘符):

 1# HookEUSER.pl
 2
 3use strict;
 4use FindBin qw($Bin);
 5
 6my $badArg = 0;
 7my $remove = 0;
 8my $platform;
 9my $release = "UDEB";
10my $arch;
11if($#ARGV >= 0)
12{
13    my $arg = 0;
14    if($ARGV[0=~ m!^[-/]r$!i)
15    {
16        $remove = 1;
17        ++$arg;
18    }
19    if($#ARGV >= $arg && $ARGV[$arg] =~ /^wins(cw)?$/i)
20      {
21           $platform = $ARGV[$arg];
22           $arch = ($platform =~ /^wins$/i)? "eka1": "eka2";
23          ++$arg;
24    }
25    while($#ARGV >= $arg && $ARGV[$arg] =~ /^(udeb|urel|eka1|eka2)$/i)
26      {
27          if($ARGV[$arg=~ /^(udeb|urel)$/i)
28          {
29               $release = $ARGV[$arg];
30        }
31        else
32        {
33            $arch = $ARGV[$arg];
34        }
35
36          ++$arg;
37    }
38    $badArg = ($#ARGV >= $arg);
39}
40
41if($badArg || !defined($platform))
42{
43    print <<USAGE_EOF;
44usage: HookEUSER.pl [-r] <PLATFORM> [RELEASE] [ARCH]
45where: <PLATFORM> == WINS | WINSCW
46       [RELEASE]  == UDEB | UREL (default == UDEB)
47       [ARCH]     == EKA1 | EKA2 (default == EKA1 for WINS, EKA2 for WINSCW)
48       -r restores original EUSER.DLL
49USAGE_EOF
50    exit(0);
51}
52
53my $path = "/Symbian/8.0a/S60_2nd_FP2_SC/epoc32/release/wins/udeb";
54chdir($path) or die "Failed setting cwd to $path";
55my $euser = "euser.dll";
56my $euser_orig = "euser.orig.dll";
57my $hooks = "EUserParasite_$arch.dll";
58my $hooks_src = "$Bin/$hooks";
59die "Can't find \"$hooks_src\"" unless -$hooks_src;
60print "Target path is $path\n";
61die "Can't find \"$euser\" - wrong drive, arguments, or EPOCROOT env var?" unless -$euser;
62if($remove)
63{
64    die "Can't find \"$euser_orig\" - was EUSER.DLL hooked by this script?" unless -$euser_orig;
65    unlink $euser or die "Can't delete hooked EUSER.DLL - is emulator (etc) running?";
66    rename($euser_orig, $euser) or die "Failed renaming $euser_orig to $euser";
67    print "Restored $euser from $euser_orig; hooks no longer in place\n";
68}
69else
70{
71    die "\"$euser_orig\" present - has EUSER.DLL already been hooked?" if -$euser_orig;
72    my $hooked_euser = "$euser.HOOKED";
73    unlink $hooked_euser;    # earlier attempt may have died with "in use", etc
74    my $cmd = "copy \"$hooks_src\"";
75    $cmd =~ tr-/-\\-;
76    system($cmd== 0 or die "Failed running \"$cmd\"";
77    $cmd = "\"$Bin/AttachDll\" $euser $hooks $hooked_euser";
78    system($cmd== 0 or die "Failed running \"$cmd\"";
79    rename $euser, $euser_orig or die "Failed renaming $euser to $euser_orig - is emulator (etc) running?";
80    rename $hooked_euser, $euser or die "Failed renaming $hooked_euser to $euser";
81    print "Modified $euser to hook $hooks, original is $euser_orig.\nRun HookEUSER with -r to restore\n";
82}
83

这样你只要安装完 HookLogger 并按照上面的方法更新 HookEUSER.pl,再按照【参考文章】运行程序就行了。
程序的使用很简单,这里不再赘述。
定位到内存泄露的地方后剩下的事就交给你了~~