hard.GCAllocatedMemory

Discussion in 'Questions (Windows Mobile)' started by alfcen, Jul 25, 2007.

  1. alfcen

    alfcen Well-Known Member Licensed User

    I'm afraid I fail to understand hardware.GCAllocatedMemory (suppose the unit is Bytes).
    All I'm trying to figure out is how much memory hardware.GCCollect releases.
    This does not make sense:

    m = hard.GCAllocatedMemory
    hard.GCCollect
    msgbox("All unused resources released" & " (" & m & " Bytes)."," Garbage Collection",cMsgBoxNone,cMsgBoxAsterisk)

    Any ideas appreciated :)
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    What are the results?
     
  3. alfcen

    alfcen Well-Known Member Licensed User

    first collection: 1483820
    next time: 1479508
    and then: 1479252
    it various, but is always in the order of 1.4 to 1.9MB
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    You have 1.4 mb of used memory.
    The GC can only free unused memory.
    When the memory reaches 1.9 mb (on your device) the GC automatically frees unused memory.
     
  5. alfcen

    alfcen Well-Known Member Licensed User

    That makes sense, thanks Erel.
    Is there any means of computing the released amount of Bytes?
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    No.
    In most cases it is better to leave the GC (garbage collector) and let it release memory automatically.
     
  7. alfcen

    alfcen Well-Known Member Licensed User

    Fair enough.
    Thanks a lot for your fast attention (as you always do).
     
  8. alfcen

    alfcen Well-Known Member Licensed User

    Sorry to bother again, Erel
    >...and let it release memory automatically.
    Does this mean that garbadge collection is automatically performed after a first use of hardware.GCCollect, say in App_Start, whenever B4PPC deems it necessary?

    I have a hardware.GCCollect in App_Start and another before AppClose, while
    the user can anytime clear using a menu.
     
  9. agraham

    agraham Expert Licensed User

    Why are you so worried about Garbage Collection? One of the points about the .NET Framework is that memory is managed for you, and B4PPC is a .NET app. The GC collects unused objects in memory automatically and frees the memory. Except in certain instaces when you have acquired resources OUTSIDE the .NET environment (which is unlikely in B4PPC) you can just let the GC do its' thing.
     
Loading...