473,795 Members | 3,279 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Visua lBasic.Collecti on
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 2590
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.c ount-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**@discussio ns.microsoft.co m> wrote in message
news:35******** *************** ***********@mic rosoft.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.Visua lBasic.Collecti on 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
1909
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 workable Collection template library. The idea is to design API's that operate on interfaces, and provide multi-implementations to that "single" API. C++ Interfaces and Implementations, seems to behave like Win32 COM objects?
19
2414
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 scitech.com, it reports reasonable memory behavior, hovering around 400k for live bytes, and peaking no higher than 1.5megs or so for total bytes used. However, looking in the task manager at the process, it reports the memory being used at around...
3
4152
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 periodically. What happens, is that the app reads the contents of a text file line by line into an ArrayList. Each element of the ArrayList is a string representing a record from the file. The ArrayList is then processed, and the arraylist goes out of...
7
11109
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 i load the dll everything is fine and when i load then the objects into an Hashtable or Arraylist of the main program it freezes 5MB each which i don't get free. The weird think is, when i reload the Tables a second time on a new local variable...
0
1402
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 creatable instances? Please forgive my use of terms. Quasi-signleton is a term I made up and static instances is a little bogus too but I don't know the correct terms for what I mean if there are any. However, I think the code below should be...
4
1678
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 sequentially (in the order stored) via "For Each". I know I could code this from scratch - or derived from a number of framework classes, but I'm not sure of the pros/cons of various possibilities. I'd like to use some of the new Generics - they are...
3
1666
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 namespace System; using namespace System::Windows::Forms;
20
6753
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 xxx = new localhost.Service1(); localhost is not recognized by the compiler.
2
3285
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 attributes successfully (ManagementKey, ManagementProbe, ManagementBind...). The only one attribute I am having problem with is ManagementCreate. As I understand from the documentation, it is supposed to support creation of new instances of a...
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10213
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10163
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9037
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6779
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.