diff --git a/include/osgIntrospection/CustomAttributeProvider b/include/osgIntrospection/CustomAttributeProvider index 228482bea..f3c7825b4 100644 --- a/include/osgIntrospection/CustomAttributeProvider +++ b/include/osgIntrospection/CustomAttributeProvider @@ -115,7 +115,11 @@ namespace osgIntrospection protected: virtual void getInheritedProviders(CustomAttributeProviderList& providers) const = 0; - virtual ~CustomAttributeProvider() {} + virtual ~CustomAttributeProvider() { + for(CustomAttributeList::iterator it = attribs_.begin(); it != attribs_.end(); ++it) { + delete (*it); + } + } private: CustomAttributeList attribs_; diff --git a/include/osgIntrospection/PropertyInfo b/include/osgIntrospection/PropertyInfo index b12e3db10..f153195e6 100644 --- a/include/osgIntrospection/PropertyInfo +++ b/include/osgIntrospection/PropertyInfo @@ -354,6 +354,8 @@ namespace osgIntrospection /// this method, for example NoDefaultValueAttribute. Value getDefaultValue() const; + virtual ~PropertyInfo() {}; + protected: virtual void getInheritedProviders(CustomAttributeProviderList& providers) const; diff --git a/include/osgIntrospection/Reflection b/include/osgIntrospection/Reflection index 91a6bf8f7..4082b2fdf 100644 --- a/include/osgIntrospection/Reflection +++ b/include/osgIntrospection/Reflection @@ -79,6 +79,11 @@ namespace osgIntrospection static const Converter* getConverter(const Type& source, const Type& dest); static bool getConversionPath(const Type& source, const Type& dest, ConverterList& conv); + // This function should be called (at least on windows platforms using Visual Studio 7.1 or 8 as compiler) to unregister + // all the known types before exiting your program: otherwise, you will get a lot of false positive memory leaks in debug builds. + // It might also be used to dynamically reload the description of the known types (?) + static void uninitialize(); + private: template friend class Reflector; template friend struct TypeNameAliasProxy; diff --git a/include/osgIntrospection/Type b/include/osgIntrospection/Type index 359e24c65..c9a73d893 100644 --- a/include/osgIntrospection/Type +++ b/include/osgIntrospection/Type @@ -253,6 +253,10 @@ namespace osgIntrospection Value createInstance(ValueList& args) const; inline Value createInstance() const; + // This function is called internally to reset all the elements contained in that type. + // used in the type loading process: it solves a false positive issue on VS 7.1 and 8 compilers in debug builds. + void reset(); + protected: Type(const ExtendedTypeInfo &ti) : _ti(ti), diff --git a/src/osgIntrospection/Reflection.cpp b/src/osgIntrospection/Reflection.cpp index 72f752f7f..521fc0217 100644 --- a/src/osgIntrospection/Reflection.cpp +++ b/src/osgIntrospection/Reflection.cpp @@ -113,12 +113,10 @@ Type* Reflection::getOrRegisterType(const ExtendedTypeInfo &ti, bool replace_if_ std::string old_namespace = i->second->getNamespace(); std::vector old_aliases = i->second->_aliases; - Type* newtype = new (i->second) Type(ti); - newtype->_name = old_name; - newtype->_namespace = old_namespace; - newtype->_aliases.swap(old_aliases); - - return newtype; + i->second->reset(); + i->second->_name = old_name; + i->second->_namespace = old_namespace; + i->second->_aliases.swap(old_aliases); } return i->second; } @@ -128,7 +126,16 @@ Type* Reflection::getOrRegisterType(const ExtendedTypeInfo &ti, bool replace_if_ void Reflection::registerConverter(const Type& source, const Type& dest, const Converter* cvt) { + const Converter* old = NULL; + StaticData::ConverterMap::iterator it = getOrCreateStaticData().convmap[&source].find(&dest); + + if(it != getOrCreateStaticData().convmap[&source].end()) + old = it->second; + getOrCreateStaticData().convmap[&source][&dest] = cvt; + + if(old) + delete old; } const Converter* Reflection::getConverter(const Type& source, const Type& dest) @@ -196,3 +203,9 @@ bool Reflection::accum_conv_path(const Type& source, const Type& dest, Converter return false; } + +void Reflection::uninitialize() { + if(_static_data) + delete _static_data; + _static_data = 0; +} diff --git a/src/osgIntrospection/Type.cpp b/src/osgIntrospection/Type.cpp index 61c6402eb..a7ad7dd5b 100644 --- a/src/osgIntrospection/Type.cpp +++ b/src/osgIntrospection/Type.cpp @@ -51,19 +51,34 @@ namespace } -Type::~Type() -{ +void Type::reset() +{ for (PropertyInfoList::const_iterator i=_props.begin(); i!=_props.end(); ++i) delete *i; for (MethodInfoList::const_iterator i=_methods.begin(); i!=_methods.end(); ++i) delete *i; + for (MethodInfoList::const_iterator i=_protected_methods.begin(); i!=_protected_methods.end(); ++i) + delete *i; for (ConstructorInfoList::const_iterator i=_cons.begin(); i!=_cons.end(); ++i) delete *i; + for (ConstructorInfoList::const_iterator i=_protected_cons.begin(); i!=_protected_cons.end(); ++i) + delete *i; + + _props.clear(); + _methods.clear(); + _protected_methods.clear(); + _cons.clear(); + _protected_cons.clear(); delete _rw; delete _cmp; } +Type::~Type() +{ + reset(); +} + bool Type::isSubclassOf(const Type& type) const { check_defined();