have created a simple script that has to create 1 million Win32 objects. The following code is what creates each object in a loop:

$DirFileObj = new Win32::Perms($SubFileDirPath);

where $SubFileDirPath is a full path that changes in every loop iteration. The problem is that every time a new object is created, more memory is used and the Win32::Perms module wont give it up, so by the time you get to 100,000 objects, you memory usage is around 1GB. I figured that since i am resetting the $DirFileObj object every loop here that the memory would be reclaimed, but that's not the case. I have tried clearing the object with the following with no success:

$DirFileObj = (); $DirFileObj = undef;

Is there a way to reclaim this memory or possibly used only one object but update the path that is associated with it in each loop iteration?

I was able to narrow the problem down to a specific thing which I believe is a memory leak in Win32::Perms. I have created a test script that theoretically loops through a million directories and uses the Dump function in Win32:Perms to produce an array called @AclInfo of all the ACL entries for each directory. That script is here:

The problem is that the Dump function uses more and more memory with each loop iteration without releasing it. This only happens when you direct the output of Dump to an Array. If you omit specifying the array ($DirFileObj->Dump()), formatted output is printed to STDOUT and no memory is used. Because @AclInfo is being re-created on each iteration, memory usage should not build on itself. I have even attempted destroying the $DirFileObj object and initializing the @AclInfo array (see the 3 commented out lines in the code above) in attempts to reclaim the memory with no success.

It appears that there is a memory leak in the Win32:Perms module, specifically in the PERLS.DLL (written in C++ I believe). I have downloaded the source for this module from ftp://www.roth.net/pub/ntperl/perms/20020605/source/Perms_Source.Zip and looked at the XS(XS_WIN32__Perms_Dump) function in PERMS.CPP. I can see where the ACE hashes that are put into the Dump array are being created, but I am not a C programmer and don't really know how modify this code to reclaim the leaked memory.

I found and verified the problem in PERMS.DLL. It is indeed a memory leak. I believe I have resolved the memory leak in PERMS.DLL, however, I am having major problems trying to compile the DLL. Taking my changes out of the mix and just attempting to compile the source of perms.dll (ftp://www.roth.net/pub/ntperl/perms/20020605/source/Perms_Source.Zip) does not work either.