PDA

View Full Version : Problem with releasing class resources while finishing application



Momergil
11th May 2013, 18:57
Hello!

Some time ago my application used to store quite a bunch of data into a QVector of structs (something like 450 Mb). When the app was finished while having the data stored it, it would happen quickly. But some time ago I changed the struct-based containing and create a similar class so I could have a better programming. Now I work with a QVector of objects from a given class. Unfortunately, since I did this change the app now takes quite a time to be actually finished after I click the MainWindow's close button - the window itself is closed, but when I go to the task manager I can see the .exe in the executable list for more two to five seconds, and this running in release mode.

I would like to know more about this situation: is it normal for this to happen? Shouldn't the change makes no effect at all? Does this means as well that my app will possibly be slower while dealing with my data, specially when I had to erase part of it while working with the app opened? Is there a way Qt provides for quick data erasing?

Thanks,

Momergil

Lykurg
11th May 2013, 19:40
Hi,

have you only substitute "struct" through "class"? No other change at all? How does the structure of the new class look like?

best

ChrisW67
12th May 2013, 09:42
I am not sure how much we can tell you about what your program is doing between when the last window closes and exit. Deleting a serious number of heap allocated objects might take some time especially if their destructor does something significant... but only you know what your program has to do, and it may not be this. It might be the orderly teardown of network or database connections.

Momergil
12th May 2013, 20:03
Hi,

have you only substitute "struct" through "class"? No other change at all? How does the structure of the new class look like?

best

You may see by yourself (only relevant data displayed):



//Old struct-based:

struct periodical_data
{
QList<time_frame> baseData;
QList<figure_congestion_rectangular> rectangles;
QList<figure_congestion_triangles> triangles;
QList<figure_channels> channels;
QList<basic_price_value> zig_zag_sequence;
QList<pivot> pivots;
};

struct share //Structure that contains all data about a share
{
periodical_data periodicity[PERIOD_MAX];
};


vs.



//New class-based:

struct periodical_data
{
QList<time_frame> baseData;
QList<figure_congestion_rectangular> rectangles;
QList<figure_congestion_triangles> triangles;
QList<figure_channels> channels;
QList<basic_price_value> zig_zag_sequence;
QList<pivot> pivots;
};

class share //Class that contains all data about a share
{
public:
explicit share() { /*does nothing*/ }
~share(); //does nothing

private:
periodical_data periodicity[PERIOD_MAX];
};


Added after 8 minutes:


Deleting a serious number of heap allocated objects might take some time especially if their destructor does something significant...
...

It might be the orderly teardown of network or database connections.

Well Chris, I wouln't be surprised if my software took some time to exit given the amount of data I load. The strange thing is that this problem didn't exist when I used structs, but it appeared when I changed it to classes. But nope, my destructor actually don't do anything. No database connections either or network issues; the only thing is the data I load from .csv files into my objects. When this is not performed, the app closes in normal speed, so to speak.

tuli
13th May 2013, 19:57
I have the same problem, and my destructors dont do anything special (in fact, there is no custom destructor).
Switched the container from QList to QVector, no change.
WHen i use std:: equivalents, i do not have this problem...

ChrisW67
13th May 2013, 21:14
What happens if you remove the do-nothing destructor? Essentially the only difference here is the presence of the destructor in the class vs struct and the corresponding call during destruction.