-
Oct 7th, 2021, 11:15 AM
#1
Thread Starter
Hyperactive Member
Sleep or Pause to reclaim resources
I have a small program that periodically checks for files in a folder. When files are found, it reads them and creates some output in the same folder. The program itself if very basic: single form, only default controls (no ocxes\api calls), a few hundred lines of code overall and the timer control in a 30 second loop.
I'm finding that over time, the exe becomes unresponsive and needs to be restarted.
The first problem was that writing to a listbox while in a timer loop doesn't seem to release memory when items are removed so the program's ram usage would just grow over time. I found a solution to periodically minimize the form via code, it does something to trigger a cleanup (i eventually just removed the listbox)
But I am still having trouble with this long running process becoming unresponsive over time. I'm thinking it has to do with the timer control and some quirk that prevents reclaiming of resources.
Is there some type of Sleep or Wait that I can use to pause things and let the system garbage collect or release references?
-
Oct 7th, 2021, 12:31 PM
#2
Re: Sleep or Pause to reclaim resources
You could try switching to a file system monitor with ReadDirectoryChanges
(requires a C DLL helper and a subclass in VB to receive the messages)
https://github.com/dzzie/SysAnalyzer...ileVer.bas#L71
https://github.com/dzzie/SysAnalyzer...ch_dll.cpp#L56
-
Oct 7th, 2021, 02:40 PM
#3
Re: Sleep or Pause to reclaim resources
Actually, I'm more curious about why this is happening. He describes the program as being simple so I'm assuming he is not using any external APIs, which means everything he is using would be normal VB6 COM objects. As far as I know none of them have leaks so why is this happening? I think this should be investigated in case there is some bug in the VB6 runtime itself or one of the standard objects commonly used in VB applications.
-
Oct 7th, 2021, 03:29 PM
#4
Re: Sleep or Pause to reclaim resources
I agree. This doesn't sound like appropriate behavior, which suggests that something isn't being cleaned up as correctly as it needs to be.
My usual boring signature: Nothing
-
Oct 7th, 2021, 03:30 PM
#5
Re: Sleep or Pause to reclaim resources
... writing to a listbox "while in a timer loop" ...
That's a puzzling phrase to me. A timer just sets a time for an event to be raised using Windows. Personally, I wouldn't call it a loop.
Now, to my way of thinking, a timer event isn't any different from any other event. So, I can't see why a listbox would behave any differently when manipulated in a timer event versus any other event. Also, when adding/deleting items from a listbox, I'd be surprised if all the "cleanup" isn't done while those methods are called.
Personally, I think your problems are elsewhere. Would there be a problem with showing us this "small program"?
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Oct 8th, 2021, 12:24 PM
#6
Re: Sleep or Pause to reclaim resources
I also suspect the problem is something else. I've had programs that ran for very long periods where they add and remove items from a list box repeatedly thousands upon thousands of items over time and have never saw any related issues arise.
-
Oct 8th, 2021, 12:35 PM
#7
Re: Sleep or Pause to reclaim resources
once in a while I have seen a folder get locked from deletion after enumerating its contents. I dont think it was a file handle issue
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|