Results 1 to 7 of 7

Thread: Sleep or Pause to reclaim resources

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    460

    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?

  2. #2
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,057

    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

  3. #3
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    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.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    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

  5. #5
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    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.

  6. #6
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    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.

  7. #7
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,057

    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
  •  



Click Here to Expand Forum to Full Width