CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Win32 Programming Help:
Win32::Perms Object and Memory Usage

 



drichfield
New User

Feb 23, 2006, 10:10 PM

Post #1 of 4 (3154 views)
Win32::Perms Object and Memory Usage Can't Post

 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?

Thanks,
Dan


drichfield
New User

Feb 24, 2006, 3:21 PM

Post #2 of 4 (3146 views)
Re: [drichfield] Win32::Perms Object and Memory Usage [In reply to] Can't Post

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:

===============================
$DirFileObj = new Win32::Perms("C:/test") || die(Win32::FormatMessage(Win32::GetLastError()));

for ($i = 0; $i <= 1000000; $i++) {

$DirFileObj->Path("C:/test") || die(Win32::FormatMessage(Win32::GetLastError()));
$DirFileObj->Dump(\@AclInfo) || die(Win32::FormatMessage(Win32::GetLastError()));

# $DirFileObj->Close();
# @AclInfo = ();
# undef @AclInfo;

}
===============================

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.

Also, the homepage for the Win32:Perms module is: http://www.roth.net/perl/perms/

Thanks,
Dan


KevinR
Veteran


Feb 26, 2006, 11:25 AM

Post #3 of 4 (3137 views)
Re: [drichfield] Win32::Perms Object and Memory Usage [In reply to] Can't Post

it looks like you are constantly adding more data into the array untill it apparently consumes a lot of memory. Have you tried something like:


Code
for ($i = 0; $i <= 1000000; $i++) { 

my @AclInfo = ();
$DirFileObj->Path("C:/test") || die(Win32::FormatMessage(Win32::GetLastError()));
$DirFileObj->Dump(\@AclInfo) || die(Win32::FormatMessage(Win32::GetLastError()));

}


this should release the memory that the array is using with each new iteration of the loop.
-------------------------------------------------


drichfield
New User

Feb 27, 2006, 4:41 PM

Post #4 of 4 (3129 views)
Re: [drichfield] Win32::Perms Object and Memory Usage [In reply to] Can't Post

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.

I have done the following:

- installed Visual Studio 6.0
- downloaded the activestate activeperl 5.6.1 source (http://aspn.activestate.com/ASPN/Downloads/ActivePerl/Source)
- added the activeperl source directory to Visual Studio in Tools -> Options -> Directories
- copied various files/folders from the perl source to the perms.dll source root directory to accomodate for missing files during the build.

After all of that, I am still getting errors during the build for files such as config.h, file.h, etc..

So my question as of now is simply, how do I compile the perms.dll source into a DLL? I am willing to use any compiler or method other than Visual Studio.

I will post my resolution once I can compile this DLL and test it to make sure it works.

Thanks,
Dan

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives