[VB, C#] GC.Collect() or EmptyWorkingSet()?

Discussion in 'Mixed Languages' started by QuantumBug, Jul 2, 2015.

  1. QuantumBug

    QuantumBug MDL Developer

    Mar 7, 2012
    1,485
    1,323
    60
    #1 QuantumBug, Jul 2, 2015
    Last edited: Jul 2, 2015
    Do any developers on here use some sort of memory management in their software?

    My question is, when is it safe to use GC.Collect() and/or EmptyWorkingSet() and which one is better? I heard GC.Collect can cause ample issues.

    I mean can they both be used at the same time? Should I only do it when a large form is closed or is it only essential after running a long task?

    I've already written my own code for an EmptyWorkingSet() task, I'm just looking for pointers on where to implement it as I'm afraid if it's placed all over the place I won't be doing the application any favors.

    Regards, The Dev.
     
  2. DougQuaid

    DougQuaid MDL Novice

    Aug 15, 2012
    30
    62
    0
    I'm using GC.Collect() when I'm working with large arrays. I set the references to them to null and then call GC.Collect() and memory gets freed. Never had any problems or performance issues with it. I've never used EmptyWorkingSet()
     
  3. QuantumBug

    QuantumBug MDL Developer

    Mar 7, 2012
    1,485
    1,323
    60
    #3 QuantumBug, Jul 2, 2015
    Last edited: Jul 2, 2015
    (OP)
    Thanks for the advice.

    EmptyWorkingSet() clears process working set memory and then the the application takes what it needs. It's good to use after application load and various other places. I think EmptyWorkingSet() might be what I need to use as opposed to GC.Collect() as I'm not handling large arrays of data, etc. Apart from when, maybe, calculating checksums on large files likes ISO's.

    I see that Windows is supposed to call the Process Status API and clear out working set memory automatically, but I've never seen this happen whilst monitoring my applications performance.

    I continue to learn and see where GC.Collect() and EmptyWorkingSet() are needed most but so far I've got a usual 14-18 Megabytes utilization down to 2-4MB.