Modify

Opened 9 years ago

Closed 3 years ago

#3135 closed Bug (Fixed)

StdioClose with $STDERR_MERGED memory leak

Reported by: jvanegmond Owned by: Jon
Milestone: 3.3.15.4 Component: AutoIt
Version: 3.3.15.0 Severity: None
Keywords: Cc:

Description

The following AutoIt code when run on my machine by AutoIt v3.3.15.0 leaks several MB of memory per minute:

#include <Constants.au3>

While 1
    $pid = Run("ping localhost","", @SW_HIDE, $STDERR_MERGED)
    ProcessWait($pid)
    StdioClose($pid)
    ProcessClose($pid)
    ProcessWaitClose($pid)
WEnd

Originally reported here https://www.autoitscript.com/forum/topic/177671-stdoutread-memory-problem-edit-and-stdioclose/

Attachments (0)

Change History (13)

comment:1 Changed 9 years ago by Jpm

If I understand well you just miss a StdIoClose($pid) at the right place
as suggested by Jos

comment:2 Changed 9 years ago by jvanegmond

Jpm, the problem is solved. However, AutoIt methods should never leak memory. They should prevent the memory leak or catch the conditions where they can leak and return and set @error instead. Doing otherwise is unnecessarily confusing and placing the burden on end-users which we should not want.

In this particular case, because the problem only happens with $STDERR_MERGED defined, I would guess it is probably an oversight inside of StdioClose or ProcessClose for that particular case.

comment:3 follow-up: Changed 9 years ago by anonymous

Agree there is a bug there somewhere.
Firstly the posted script is what the helpfile also advertises and has a memory leak, but it seems there is also a leak when you comment the StdioClose()statement. Could it be that ProcessClose() isn't cleaning up when STDIO is used for the process?

Jos

Last edited 9 years ago by Jos (previous) (diff)

comment:4 in reply to: ↑ 3 Changed 9 years ago by jvanegmond

Replying to anonymous:

but it seems there is also a leak when you comment the StdioClose()statement. Could it be that ProcessClose() isn't cleaning up when STDIO is used for the process?

Interestingly, the only order which does seem to work is the exact one you posted on the forum where you call StdioClose after ProcessWaitClose. Any other order and it leaks memory.

comment:5 Changed 9 years ago by Jos

Correct or the other option is to replace the StdioClose() by a loop that reads the STDIO buffer until it has read everything. This will also avoid the leaking.

Jos

comment:6 Changed 9 years ago by Jpm

For me the StdIoClose() can do a definitive cleaning only if the process is really close so that normal it should be post after to have a complete cleaning
The Stream reading must be available by StdOutRead() or StdErrRead() after the process closing. So If you don't do it StdIoClose() will do it for you.

I hope I understand the AutoIt implementation. I leave to Jon the final answer

comment:7 Changed 9 years ago by Valik

JP, the documentation clearly states that StdioClose() releases all resources. It shouldn't matter if the process is closed or not, AutoIt should internally close the handles and release any buffers.

It's been years since I wrote the STDIO code and I don't have access to it any longer (and it may have changed in the years since I left the project). I have an idea where the leak may be, though. Remember that when the buffer fills up the child program and AutoIt will deadlock. There's a pretty good chance I wrote the feature to always read the buffer and store the data internally to prevent the deadlock. I suspect it may be this internal buffer that's causing the problem. It's probably being dynamically allocated on each call which could theoretically cause an artificial inflation in the working set.

comment:8 Changed 9 years ago by Jpm

Thanks Valik for the info just PM me if you want I PM you the actual code you re thinking about
Cheers

comment:9 Changed 9 years ago by Valik

Sorry, JP. I'm not interested in looking at the code.

comment:10 Changed 9 years ago by Jpm

Anyway thanks Valik for the info
Cheers

comment:11 Changed 7 years ago by Jpm

  • Owner set to Jon
  • Status changed from new to assigned

comment:12 Changed 4 years ago by Jpm

  • Owner changed from Jon to Jpm

Fix sent to Jon

comment:13 Changed 3 years ago by Jon

  • Milestone set to 3.3.15.4
  • Owner changed from Jpm to Jon
  • Resolution set to Fixed
  • Status changed from assigned to closed

Fixed by revision [12557] in version: 3.3.15.4

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The owner will remain Jon.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.