[Kst] branches/work/kst/portto4/kst/src
Barth Netterfield
netterfield at astro.utoronto.ca
Mon Dec 7 21:46:44 CET 2009
SVN commit 1059986 by netterfield:
Fix some memory handling stuff:
-KSharedPtr does actually work, so keep it.
-You shouldn't be deleting things held by a KSharedPtr - let the Ptr do the work.
-You shouldn't be increasing the reference of a KSharedPtr by hand. Just hold a Ptr to it instead.
This gets rid of crash on exit, and makes sure that scalars, etc actually get deleted on exit.
There are still some un-gaurded pointers kicking around though.
M +2 -2 libkst/datavector.h
M +3 -3 libkst/matrix.cpp
M +2 -2 libkst/matrix.h
M +0 -3 libkst/object.cpp
M +16 -22 libkst/vector.cpp
M +4 -4 libkst/vector.h
M +2 -3 libkstapp/application.cpp
--- branches/work/kst/portto4/kst/src/libkst/datavector.h #1059985:1059986
@@ -151,8 +151,8 @@
bool _dontUseSkipAccel;
- QHash<QString, Scalar*> _fieldScalars;
- QHash<QString, String*> _fieldStrings;
+ QHash<QString, ScalarPtr> _fieldScalars;
+ QHash<QString, StringPtr> _fieldStrings;
friend class TestDataSource;
friend class TestHistogram;
--- branches/work/kst/portto4/kst/src/libkst/matrix.cpp #1059985:1059986
@@ -66,7 +66,7 @@
void Matrix::deleteDependents() {
- for (QHash<QString, Scalar*>::Iterator it = _statScalars.begin(); it != _statScalars.end(); ++it) {
+ for (QHash<QString, ScalarPtr>::Iterator it = _statScalars.begin(); it != _statScalars.end(); ++it) {
_store->removeObject(it.value());
}
}
@@ -295,7 +295,7 @@
int Matrix::getUsage() const {
int scalarUsage = 0;
- for (QHash<QString, Scalar*>::ConstIterator it = _statScalars.begin(); it != _statScalars.end(); ++it) {
+ for (QHash<QString, ScalarPtr>::ConstIterator it = _statScalars.begin(); it != _statScalars.end(); ++it) {
scalarUsage += it.value()->getUsage() - 1;
}
return Object::getUsage() + scalarUsage;
@@ -351,7 +351,7 @@
}
-const QHash<QString, Scalar*>& Matrix::scalars() const {
+const QHash<QString, ScalarPtr>& Matrix::scalars() const {
return _statScalars;
}
--- branches/work/kst/portto4/kst/src/libkst/matrix.h #1059985:1059986
@@ -110,7 +110,7 @@
virtual void save(QXmlStreamWriter &s);
// the statistics scalars for this matrix
- const QHash<QString, Scalar*>& scalars() const;
+ const QHash<QString, ScalarPtr>& scalars() const;
// set the labels for this matrix
void setLabel(const QString& newLabel);
@@ -151,7 +151,7 @@
double _stepX;
double _stepY;
int _numNew; // number of new samples
- QHash<QString, Scalar*> _statScalars; // statistics scalars
+ QHash<QString, ScalarPtr> _statScalars; // statistics scalars
bool _editable : 1;
bool _saveable : 1;
--- branches/work/kst/portto4/kst/src/libkst/object.cpp #1059985:1059986
@@ -32,9 +32,6 @@
Object::~Object() {
- if (_store) {
- _store->removeObject(this);
- }
}
--- branches/work/kst/portto4/kst/src/libkst/vector.cpp #1059985:1059986
@@ -86,17 +86,11 @@
void Vector::deleteDependents() {
- for (QHash<QString, Scalar*>::Iterator it = _scalars.begin(); it != _scalars.end(); ++it) {
+ for (QHash<QString, ScalarPtr>::Iterator it = _scalars.begin(); it != _scalars.end(); ++it) {
_store->removeObject(it.value());
- if (it.value()->getUsage() == 0) {
- delete it.value();
- }
}
- for (QHash<QString, String*>::Iterator it = _strings.begin(); it != _strings.end(); ++it) {
+ for (QHash<QString, StringPtr>::Iterator it = _strings.begin(); it != _strings.end(); ++it) {
_store->removeObject(it.value());
- if (it.value()->getUsage() == 0) {
- delete it.value();
- }
}
}
@@ -257,47 +251,47 @@
_scalars.insert("max", sp = store->createObject<Scalar>());
sp->setProvider(this);
sp->setSlaveName("Max");
- sp->_KShared_ref();
+
_scalars.insert("min", sp = store->createObject<Scalar>());
sp->setProvider(this);
sp->setSlaveName("Min");
- sp->_KShared_ref();
+
_scalars.insert("last", sp = store->createObject<Scalar>());
sp->setProvider(this);
sp->setSlaveName("Last");
- sp->_KShared_ref();
+
_scalars.insert("first", sp = store->createObject<Scalar>());
sp->setProvider(this);
sp->setSlaveName("First");
- sp->_KShared_ref();
+
_scalars.insert("mean", sp = store->createObject<Scalar>());
sp->setProvider(this);
sp->setSlaveName("Mean");
- sp->_KShared_ref();
+
_scalars.insert("sigma", sp = store->createObject<Scalar>());
sp->setProvider(this);
sp->setSlaveName("Sigma");
- sp->_KShared_ref();
+
_scalars.insert("rms", sp = store->createObject<Scalar>());
sp->setProvider(this);
sp->setSlaveName("Rms");
- sp->_KShared_ref();
+
_scalars.insert("ns", sp = store->createObject<Scalar>());
sp->setProvider(this);
sp->setSlaveName("NS");
- sp->_KShared_ref();
+
_scalars.insert("sum", sp = store->createObject<Scalar>());
sp->setProvider(this);
sp->setSlaveName("Sum");
- sp->_KShared_ref();
+
_scalars.insert("sumsquared", sp = store->createObject<Scalar>());
sp->setProvider(this);
sp->setSlaveName("SumSquared");
- sp->_KShared_ref();
+
_scalars.insert("minpos", sp = store->createObject<Scalar>());
sp->setProvider(this);
sp->setSlaveName("MinPos");
- sp->_KShared_ref();
+
}
}
@@ -321,12 +315,12 @@
}
-const QHash<QString, Scalar*>& Vector::scalars() const {
+const QHash<QString, ScalarPtr>& Vector::scalars() const {
return _scalars;
}
-const QHash<QString, String*>& Vector::strings() const {
+const QHash<QString, StringPtr>& Vector::strings() const {
return _strings;
}
@@ -558,7 +552,7 @@
int Vector::getUsage() const {
int adj = 0;
- for (QHash<QString, Scalar*>::ConstIterator it = _scalars.begin(); it != _scalars.end(); ++it) {
+ for (QHash<QString, ScalarPtr>::ConstIterator it = _scalars.begin(); it != _scalars.end(); ++it) {
adj += it.value()->getUsage() - 1;
}
return Object::getUsage() + adj;
--- branches/work/kst/portto4/kst/src/libkst/vector.h #1059985:1059986
@@ -136,8 +136,8 @@
/** access functions for _isScalarList */
bool isScalarList() const { return _isScalarList; }
- const QHash<QString, Scalar*>& scalars() const;
- const QHash<QString, String*>& strings() const; // used by datavector
+ const QHash<QString, ScalarPtr>& scalars() const;
+ const QHash<QString, StringPtr>& strings() const; // used by datavector
void setLabel(const QString& label_in);
@@ -175,10 +175,10 @@
int NumNew;
/** Statistics Scalars */
- QHash<QString, Scalar*> _scalars;
+ QHash<QString, ScalarPtr> _scalars;
/** Dependent Strings: used by datavector */
- QHash<QString, String*> _strings;
+ QHash<QString, StringPtr> _strings;
/** is the vector monotonically rising */
bool _is_rising : 1;
--- branches/work/kst/portto4/kst/src/libkstapp/application.cpp #1059985:1059986
@@ -57,9 +57,8 @@
// lets not clean up before we leave....
// if we do, we'll end up crashing on exit
// unless we fix some stuff related to destruction
- // in a multi-threaded situation.
- //delete _mainWindow;
- //delete _dialogDefaults;
+ delete _mainWindow;
+ delete _dialogDefaults;
}
More information about the Kst
mailing list