My test code looks like this: ----------------------------------------------------------------- KDOM::SharedVector v2; { Q_ASSERT(BuiltinTypes::xsDouble); Q_ASSERT(BuiltinTypes::xsInteger); KDOM::SharedVector v1(2); v1.insert(0, BuiltinTypes::xsDouble); v1.insert(1, BuiltinTypes::xsInteger); CHECK(v1.count(), static_cast(2)); CHECK(v1.at(0)->xdtMatchesType(BuiltinTypes::xsDouble), true); CHECK(v1.at(1)->xdtMatchesType(BuiltinTypes::xsInteger), true); v1 = v2; } CHECK(v2.count(), static_cast(2)); Q_ASSERT(v2.at(0)); /* CRASH, gdb reports SIGSEGV, valgrind says "Invalid read of size 4 [...] Address 0x0 is not stack'd, malloc'd or (recently) free'd" */ ----------------------------------------------------------------- All tests works up until the Q_ASSERT, where it crashes. Valgrind reports the address "0x0", but if the value at position 0(which the at() function should return) is 0, the assert should fail(print message), but not crash, AFAICT. The SharedVector class looks like this: ----------------------------------------------------------------- template class SharedVector : public QValueVector { public: SharedVector(typename QValueVector::size_type n, const T& val = T()) : QValueVector(n, val) { } SharedVector(const SharedVector & l) : QValueVector(l) { typename SharedVector::const_iterator it; typename SharedVector::const_iterator end(l.constEnd()); for(it = l.constBegin(); it != end; ++it) { Q_ASSERT((*it)); if(*it) (*it)->ref(); } } SharedVector() : QValueVector() { } virtual ~SharedVector() { clear(); } virtual void clear() { typename SharedVector::iterator it; for(it = begin(); it != end(); ++it) if((*it)) (*it)->deref(); QValueVector::clear(); } virtual void append(const T item) { Q_ASSERT(item); if(!item) return; const_cast(item)->ref(); QValueVector::append(item); } void insert(typename QValueVector::size_type pos, const T& x) { T item = QValueVector::operator[](pos); if(item) item->deref(); Q_ASSERT(x); x->ref(); QValueVector::operator[](pos) = x; } SharedVector& operator+=(const SharedVector& l) { typename SharedVector::const_iterator it; typename SharedVector::const_iterator end(l.constEnd()); for(it = l.constBegin(); it != end; ++it) append((*it)); return *this; } SharedVector& operator=(const SharedVector& l) { kdDebug(26560) << k_funcinfo << endl; typename SharedVector::const_iterator it; typename SharedVector::const_iterator end(l.constEnd()); for(it = l.constBegin(); it != end; ++it) { Q_ASSERT((*it)); if(*it) (*it)->ref(); } QValueVector::operator=(l); return *this; } protected: /** * Overriden as protected, such that reference counting is handled * properly. Use insert() instead. */ typename QValueVector::reference operator[](typename QValueVector::size_type s) { return QValueVector::operator[](s); } }; };