Using For-Each with a collection keeps increasing the size of m_iterator.

  • Thread starter Thread starter Ken Dopierala Jr.
  • Start date Start date
K

Ken Dopierala Jr.

Hi,
I have a collection that I use to keep track of bullets flying across
the screen in a game. Everytime through the foreach the m_Iterator internal
array keeps getting bigger and never seems to clear. I remove the bullets
when they go out of site and they do get removed from the collection because
the Count property only shows 4-5 bullets max. But the m_Iterator never
gets rid of them. Is there a workaround for this using the Collection
object? Has anyone else seen this? Thanks! Ken.
 
Hi Ken,

We need some code, methinks.

The next post contains a 61K image (for those who want to avoid te
download).

No, I'm not telling you - it's a surprise.;-)

Regards,
Fergus
 
Hi,
I have a collection that I use to keep track of bullets flying across
the screen in a game. Everytime through the foreach the m_Iterator internal
array keeps getting bigger and never seems to clear. I remove the bullets
when they go out of site and they do get removed from the collection because
the Count property only shows 4-5 bullets max. But the m_Iterator never
gets rid of them. Is there a workaround for this using the Collection
object? Has anyone else seen this? Thanks! Ken.

Well without seeing code, I would guess your trying to remove elements
in the for each loop. You can't do that. A collection is read-only
when it is in a for each.

Tom Shelton
 
Ken Dopierala Jr. said:
Hi,
I have a collection that I use to keep track of bullets flying
across
the screen in a game. Everytime through the foreach the m_Iterator
internal array keeps getting bigger and never seems to clear. I
remove the bullets when they go out of site and they do get removed
from the collection because the Count property only shows 4-5 bullets
max. But the m_Iterator never gets rid of them. Is there a
workaround for this using the Collection object? Has anyone else
seen this? Thanks! Ken.

Which VB version do you use?

Bug should've been fixed:
http://groups.google.com/groups?lr=...a14a4&seekm=udbxX7ggCHA.564@tkmsftngp10#link1
 
Fergus Cooney said:
Doh!! (a clue) - Except that I forgot to post it!!

Are you sure you have the rights to distribute the image in the groups?

;-)
 
Hi Tom,
It also happens in my target collection in which Remove is never called.
It is simply iterated through 70-110 times a second. I switched everything
over to an arraylist and that works good. Ken.
 
Hi Armin,
I read that before I posted. It seems that the bug was never fixed.
They must've been talking about VB.Net 2003 even though that message is very
old. Ken.
 
Back
Top