Re: Releasing memory (continuation)

From: Tony Proctor (tony_proctor_at_aimtechnology_NoMoreSPAM_.com)
Date: 09/28/04


Date: Tue, 28 Sep 2004 10:55:46 +0100

Your last question is easy: It deletes the process and it's virtual address
space. If you kill the process with TerminateProcess then their is no
object-level cleanup, only very basic cleanup to release certain resources
back to the O/S.

The process heap(s) are process-specific. Memory is only returned to the
heap when it is explicitly deallocated, and may then be used to service
subsequent allocation requests within that process. When the process is
terminated, *all* the virtual address space is torn down: any physical
memory and paging file resources are returned to the O/S. It doesn't waste
time messing with stuff inside the heap because it was merely a process
entity.

However, if the process were terminated with a WM_CLOSE message then the
situation may be different. The application is then taking responsibility
for tearing down its own objects, and so the heap will be accessed.

Many systems allow memory to be allocated from separate heaps (sometimes
called zones). This has a number of advantages: In a multi-threaded
environment, each thread has items allocated from its own heap, thus
reducing thread contention (see the 'Hoard' memory allocator for instance).
Also, memory can be reclaimed in one operation by simply deleting the heap,
rather than returning every single memory packet back to a single heap.

            Tony Proctor

"nisant" <nisant@discussions.microsoft.com> wrote in message
news:4BD578E1-9C58-421E-AA4F-BA7AEF6B1B84@microsoft.com...
> I "refresh" the thread
>
http://communities2.microsoft.com/communities/newsgroups/en-us/default.aspx?&guid=&sloc=en-us&dg=microsoft.public.vb.general.discussion&p=1&tid=9e29a210-89db-40ef-80b7-77f42b00681a
>
> because many solutions have been proposed and I wanted to verify and give
> results to the ng.
>
> I verified objects collection vs objects array (no doubt about the fact
that
> UDTs array would be the fastest).
>
> That's what appened working with 100000 instances:
>
> OBJECTS COLLECTION
> --------
> Dim coll As New Collection
>
> For i = 0 To 100000
> coll.Add New myObject, CStr(i)
> Next i
> Allocation: 8 seconds
>
>
> For i = 0 To 100000
> coll.Remove CStr(i)
> Next i
> Release: 35 seconds
>
>
> For i = 0 To 100000
> coll.Remove 1
> Next i
> Release: 33 seconds
>
>
> For i = 100000 To 0 Step -1
> coll.Remove i
> Next i
> Killed after 2 minutes, only about 10000 objects released
>
> For i = 100000 To 0 Step -1
> coll.Remove CStr(i)
> Next i
> Release: 34 seconds
>
> Set coll = Nothing
> Release: 32 seconds
>
>
> OBJECTS ARRAY
> -------
> Dim arr(100000) As myObject
>
> For i = 0 To UBound(arr, 1)
> Set arr(i) = New myObject
> Next i
> Allocation: 2 seconds
>
> For i = 0 To UBound(arr, 1)
> Set arr(i) = Nothing
> Next i
> Release: 17 seconds
>
> For i = UBound(arr, 1) To 0 Step -1
> Set arr(i) = Nothing
> Next i
> Release: 17 seconds
>
> I also tried a dynamic array released by Redim arr(0); same elapsed as
above:
> Allocation: 2 seconds
> Release: 17 seconds
>
> COMMENTS:
>
> a) Arrays are very faster than Collections
>
> b) Rank
> 1 - Set coll = Nothing
> 2 - Removing 1st ordinal item
> 3 - Removing in reversed key order
> 4 - Removing in key order
> 5 - Removing in reversed ordinal order (geologic time)
>
> c) Release time in collection test seems to be spent 1/2 navigating thru
the
> collection, 1/2 releasing memory. Total time about 34 seconds, only 17
> seconds the memory release time, as derived from array test (where non
> navigation occurs).
>
> d) It seems that nothing can speed up memory release of instances (arrays
> perform better because there is no collection structure to navigate thru,
but
> memory release time remains the same).
>
> So one question remains I can't imagine the answer:
>
> What does system do to release the process memory instantly when I kill
the
> process?
>
> Many many many thanks for an answer.
>
> PS
> About Scripting.Dictionary:
> I hope I will try soon
>
> About SQL Server:
> My in-memory DB is loaded from a disk database (MS Access).
> I choose an in-memory structure to process data because of speed needs
>
> Tank you nevertheless.



Relevant Pages

  • Re: Whats the difference between the heap and the freestore?
    ... >> In general, when discussing dynamically allocated memory, I hear people ... As of a couple of days ago, I though the heap ... > When you use the term heap in the context of memory allocation it annoys ... > without saying that they have to be allocated on a stack or anything else. ...
    (comp.lang.cpp)
  • Memory problems - WinDbg and SOS: Who recognizes this pattern?
    ... Last night I managed to get a memory dump using ADPlus and I analyzed it ... ephemeral segment allocation context: none ... Large object heap starts at 0x0a0d0030 ...
    (microsoft.public.dotnet.framework.performance)
  • Re: Tip Required on Dynamic Memory Allocation in Server Applications ...
    ... a memory allocation failure after 300 usages of the string ... Suggestions where given to pre-reserve the size of the heap, ... My program works untill 200-300 requests are ...
    (microsoft.public.win32.programmer.kernel)
  • Re: C++ Garbage Collector on VMS?
    ... case of a reference counting system, have a non-zero reference count) as ... to the beginning of the heap, updating the pointers to the objects as it ... (segregating allocation areas by type/size can help a lot there, ... any way with GC-controlled memory). ...
    (comp.os.vms)
  • Re: Wonder why GC has only 2 generations ... here is the answer.
    ... > native allocation, and can help your application improve performance. ... > The GC maintains a list of roots, which point into the GC heap. ... of moving large areas of memory outweighs the amount of memory that would be ...
    (microsoft.public.dotnet.academic)

Loading