473,378 Members | 1,309 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 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 2571
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: SenderX | last post by:
I am a basically a life-long Win32 C programmer specializing in high-end winsock servers. Before I dive into portable C++ programming, I wanted to code up an example of what I thought would be a...
19
by: jack.mott | last post by:
I am having a strange memory issue in my server application. This application accepts socket connections, passes messages around, then closes them. Using the .NET memory profiler from...
3
by: Ian Taite | last post by:
Hello, I'm exploring why one of my C# .NET apps has "high" memory usage, and whether I can reduce the memory usage. I have an app that wakes up and processes text files into a database...
7
by: Matthias Kwiedor | last post by:
Hi@all! I have a app (c#) where i load up a external dll (managed code from c#) with a small arraylist and hashtable in two routines (about 40000 objects in each arraylist and hashtable). If...
0
by: Kenneth Baltrinic | last post by:
Is the following code correct for serializing a quasi-single class, that is a class that has a descreet (though more than one, so not a true singleton) number of static instances and no dynamically...
4
by: Mark | last post by:
I want to create a collection class that will be strongly typed (store a specific object type), be keyed with a case insensitive string, and be able to access objects stored by index, or...
3
by: caracolito1975 | last post by:
Hi to every one!!!! For some time now I'm programing in .NET and I have a question in using ListBox I need to databind a collection to a ListBox. My code is something like this: using...
20
by: =?Utf-8?B?cmtibmFpcg==?= | last post by:
I was executing the steps given in http://suppor.microsoft.com/kb/308359 for testing a sample web service application. However, the following line gives a compilation error: localhost.Service1...
2
by: =?Utf-8?B?dXJrZWM=?= | last post by:
I am trying to create an in-process WMI provider using System.Management.Instrumentation namespace. For testing I use a simple class as a wrapper for FileInfo class. I have been able to use all...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.