Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

shutting down program takes 5 minutes

Status
Not open for further replies.

koloite

Programmer
May 4, 2001
4
NL

I have made an application in VB that reads approx 30000 records and stores them in classes. All classes are set to Nothing when they are no longer needed.
When I try to close the program this takes several minutes while my harddrive is going bonanza... The problem is not related to the databases, but to the amount of objects. I have tried to make several different test programs and my conclusion is that VB can't work very well with this amount of objects. Does anyone know of a method to more efficently clean up the objects? Or a way to abruptly kill the process after closing the open connections?
 
The delay in the shut down and the harddrive activity is due to your PC using the Swap File to swap memory out.
You could try the TerminateProcess API and just call end, but not cleaning up after a program ends will produce a massive memory leak. The real issue here is the amount of objects that you are creating . . . 30,000 objects are far too many objects to create unless you really need them. You may want to revisit you application design and see if there is a way to do what you need without creating so many objects. - Jeff Marler B-)
 

I REALLY need all those objects. I have already considered switching to custom types and placing these in arrays, but this causes quite a lot of other problems because of the complexity of the program. What I would like to do is first closing all database connections and other connections, and then, before the program starts going completely nuts, calling TerminateProcess. I have tried to call TerminateProcess from within the program, but it does work for me. Can I only call TerminateProcess from another program that has started the program to terminate? Or can I call TerminateProcess for the currently running program?
 
I don't know if TerminateProcess will work from within the process that you are terminating, but I really think that it will be a bad idea to try to kill the process without letting it cleanup. As for the TerminateProcess call, be sure that you have a process handle that gives you Terminate_Process rights . . . you can get that with the OpenProcess API.
As far as the amount of objects that you are working with, tell me this . . . are you basically generating a recordset off of a database and then generating objects for each record returned from the query? Because if that is what you are doing, there is a more efficient way to do this and still make it appear that you have multiple objects for each record.
- Jeff Marler B-)
 

Hmm... I'll try the OpenProcess() -> TerminateProcess() -> CloseHandle() option. The program will mostly only be stopped when the computer is to be shut down meaning that memory leaks are not that bad... (Argh... I really don't like this)

Anyways, what other option are you thinking of instead of using the objects. I have already tried arrays of user-defined types, but this has some other drawbacks. The management of the arrays is quite hard when adding and deleting records, and also the records are grouped into eached other.

But thanks for the suggestions!
 
Real Quick (then have to run to work) . . .

1) Create a Custom Collection Class that will hold a disconnected recordset that contains your 30,000 records

2) Implement a NewEnum method to allow you to enumerate through the custom collection. Also, add Item, MoveFirst, MoveLast, etc.

3)Request objects off of the custom collection class just as you would from the current collection object that you are using.

4)The colection class will generate a new object for you and populate just that 1 item. This code is encapsulated inside of the custom collection class, so from the outside, it should look pretty similar to what you are doing right now.



This is just a quick run through . . . this method can be made as complicated as needed (i.e. hirarchial structrues), but it is much better and quicker than trying to create and destroy 30,000 object.
Speaking of creating, how long is it taking to create those 30,000 objects and how much memory does your system use while the app is running? - Jeff Marler B-)
 

I am afraid that it won't work for this application. First of all the objects are not contained in one collection, but rather as tags to several listviews and treeviews. Earlier I had the objects contained in collections (the program had the same problem even worse back then... ). If I was to keep the records in the recordsets and making a custom collection class that looks up the record the program would be too slow... The problem is that when the user wants to see a record, this record mostly contains a lot of other records, and he/she may not be permitted to see all of these records, so the permission records would need to be looked etc... I've tried, and it was quite simply not fast enough. At the moment the application starts in about 1.5 minutes, and in this time it creates all objects, groups them, sorts them and lists them... Quitting the program takes a lot longer (5 minutes is not completely accurate, it actually takes longer... :-( )

The program does not take up extremely much memory, and I have also tried to run the program on another computer with 192 MB of RAM, and it still had the same problem... I'm afraid that TerminateProcess() is the only solution at the moment to quit it in reasonble time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top