Gustavo Tabares wrote:
> Hi all,
>
> I'm having a problem when opening and enumerating a network resource
> many times.  For example:
>
> i = 0
>
> while i < 10000:
>        handle =
> win32wnet.WNetOpenEnum(win32netcon.RESOURCE_CONNECTED,
> win32netcon.RESOURCETYPE_ANY, 0, None)
>        partial_nr_list = win32wnet.WNetEnumResource(handle)
>        while partial_nr_list:
>            partial_nr_list = win32wnet.WNetEnumResource(handle)
>        win32wnet.WNetCloseEnum(handle)
>
>        i += 1
>
>
> This eventually fails with:
>
> Traceback (most recent call last):
>  File "C:\qtest.py", line 17, in <module>
>    partial_nr_list = win32wnet.WNetEnumResource(handle)
> MemoryError: VirtualAlloc error in WNetEnumResource
>   

Sure enough, if you watch this application in Task Manager, you can see
the memory usage going up smoothly over time.  On my system, however,
10,000 iterations is not nearly enough; memory usage rises to about 6MB,
and then it terminates normally.

Also, it's definitely the WNetEnumResource call that does it.  If you
comment that out, there's no leak.  It doesn't seem to be a Python
garbage issue; I added a forced garbage collection in every loop, and it
still happened.

I haven't found any web articles about this.  Very interesting...

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to