471,594 Members | 1,711 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,594 software developers and data experts.

Correct Usage of Collections?

I'm currently working on a report to forecast production for finished goods.
The user can select one or more items to forecast. In addition, they may
select one or more warehouses to view breakdowns for as well as one or more
customers.

Now, the report iterates through the selected items in the finished good
listbox. For each item that it comes across, it calls 4 routines to gather
various totals. Each routine will gather a total for the item as well as
totals for each selected warehouse and customer.

So, for example, a routine could possibly read 100 records that match a
specific item. A total will be calculated for all 100 records for the
finished good item. Let's say, of those 100 records, 25 are for warehouse A,
25 for warehouse B, 25 for C and 25 for D. Of that 100, 50 are for Customer
1 and 50 for Customer 2. To help keep track of the warehouse and customer
totals, I decided to use collections. That way, I could gather the totals,
hold them in the collections and retrieve them by a key (the warehouse letter
or customer number).

Here's the problem. When the program runs, just before the user clicks the
Print button, the memory usage is at around 25MB. As the program runs, the
memory usage climbs at a steady pace. The highest I've seen it go is close
to 180MB when the users select all criteria for the report.

I've used collections in other languages before but I'm new to .NET
collections. In this report, I am using the Microsoft.VisualBasic.Collection
collection.

First, I've noticed that you can only Add or Remove items; you cannot edit
entries in the collection. To add each quantity that I come across, I have
to retrieve the value for the warehouse/customer, add the quantity to it,
remove the entry from the collection and add the new value to the collection.

Second, I've noticed that there is no Clear() method on this type of
collection. To clear the collection, I have to iterate through the items in
the collection and remove each entry. I assume that, with the memory usage
climbing, memory is not freed when I remove an entry and replace it with
another.

I would like to keep using collections because it is so easy to retrieve the
entries by a key value. However, the memory usage is bothering me. I've
tried setting the collections to Nothing and reinstantiating them but the
memory usage still climbs.

Am I using the collections correctly? Is there another type of collection
that will allow me to Clear() the entries? Even if there is another type,
would the memory usage drop?

Any help would be greatly appreciated.
Nov 21 '05 #1
1 2469
Hi Tim

You haven't told us what your collecting? i.e What object type?
VB.Net is object oriented so you can easily add your own methods for this
by simply extending the collectionBase base class.
Depending on object type i would be looking at implementing the IDisposable
interface. Clearing the collection is all well and good but it sounds like
your not correctly disposing of your objects.

Object editing cannot be accomplished via For Each iteration but can via
For i=0 to (mycollection.count-1) iteration.

This all sounds a little messy. Are you sure you cant calculate this info
using some intermediate SQL? Sounds like a classic Group By (Totals) to me.

Richard

"Tim T." <Ti**@discussions.microsoft.com> wrote in message
news:35**********************************@microsof t.com...
I'm currently working on a report to forecast production for finished goods. The user can select one or more items to forecast. In addition, they may
select one or more warehouses to view breakdowns for as well as one or more customers.

Now, the report iterates through the selected items in the finished good
listbox. For each item that it comes across, it calls 4 routines to gather various totals. Each routine will gather a total for the item as well as
totals for each selected warehouse and customer.

So, for example, a routine could possibly read 100 records that match a
specific item. A total will be calculated for all 100 records for the
finished good item. Let's say, of those 100 records, 25 are for warehouse A, 25 for warehouse B, 25 for C and 25 for D. Of that 100, 50 are for Customer 1 and 50 for Customer 2. To help keep track of the warehouse and customer totals, I decided to use collections. That way, I could gather the totals, hold them in the collections and retrieve them by a key (the warehouse letter or customer number).

Here's the problem. When the program runs, just before the user clicks the Print button, the memory usage is at around 25MB. As the program runs, the memory usage climbs at a steady pace. The highest I've seen it go is close to 180MB when the users select all criteria for the report.

I've used collections in other languages before but I'm new to .NET
collections. In this report, I am using the Microsoft.VisualBasic.Collection collection.

First, I've noticed that you can only Add or Remove items; you cannot edit entries in the collection. To add each quantity that I come across, I have to retrieve the value for the warehouse/customer, add the quantity to it,
remove the entry from the collection and add the new value to the collection.
Second, I've noticed that there is no Clear() method on this type of
collection. To clear the collection, I have to iterate through the items in the collection and remove each entry. I assume that, with the memory usage climbing, memory is not freed when I remove an entry and replace it with
another.

I would like to keep using collections because it is so easy to retrieve the entries by a key value. However, the memory usage is bothering me. I've
tried setting the collections to Nothing and reinstantiating them but the
memory usage still climbs.

Am I using the collections correctly? Is there another type of collection that will allow me to Clear() the entries? Even if there is another type, would the memory usage drop?

Any help would be greatly appreciated.

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Matthias Kwiedor | last post: by
reply views Thread by Kenneth Baltrinic | last post: by
4 posts views Thread by Mark | last post: by
3 posts views Thread by caracolito1975 | last post: by
20 posts views Thread by =?Utf-8?B?cmtibmFpcg==?= | last post: by
2 posts views Thread by =?Utf-8?B?dXJrZWM=?= | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.