Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

takes a long time to release memory

1 view
Skip to first unread message

Michaelov, Itzik

unread,
May 4, 2008, 3:23:33 AM5/4/08
to
I'm using VB 6.0 SP6
why in second case memory release very slowly

Case 1: (execution time 2 seconds)
Dim mcol As New Collection
Dim k As Collection
For lCount = 1 To 120000
Set k = New Collection
mcol.Add k
Next
lCount = mcol.Count
For lIndex = 1 To lCount
mcol.Remove 1
Next lIndex
Set mcol = Nothing


Case 2: (execution time 30 seconds)
Dim mcol As New Collection
Dim k As Collection
For lCount = 1 To 120000
Set k = New Collection
mcol.Add k
Next
lCount = mcol.Count
For lIndex = lCount To 1 Step -1
mcol.Remove lIndex
Next lIndex
Set mcol = Nothing


Thanks

Message has been deleted
Message has been deleted

Larry Serflaten

unread,
May 4, 2008, 8:07:08 AM5/4/08
to

"Michaelov, Itzik" <IMic...@ingrnet.com> wrote

> why in second case memory release very slowly

Accessing a collection by index number is supported, but not very well
optimized. If you are using an index, then an array may be better for the
task.

FYI: Try that same test using a key value:


> mcol.Add k "k" & Cstr(lcount)

... then ...
> mcol.Remove "k" & Cstr(lIndex)


Do you notice a difference? What does that tell you about indexing and
keys when using a collection?

LFS


0 new messages