[omniORB] OmniORB3.01 - Reducing memory leaks - patch 3
Jeroen.Dobbelaere@MMR.be
Jeroen.Dobbelaere@MMR.be
Fri, 15 Sep 2000 16:20:06 +0100
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_000_01C01F28.6E1E57A0
Content-Type: text/plain;
charset="ISO-8859-1"
Hi again,
This patch takes care of the static _nil objects which are always created
for each 'interface' (once _nil() is called).
The changes involve :
- CORBA.h : adding code so that newly created _nil objects can be tracked
(through a template function)
- omniInternal.cc : the tracker itself. This is also the location where the
cleanup of those objects will happen.
- src/lib/OmniORB3/omniidl_be/cxx/skel/template.py : add registration of the
_nil objects
Because this patch changes omniidl, following build procedure should be
followed :
- make veryclean
- make export
Programs which want to use this functionality, should be built with the new
omniidl and CORBA.h
(Don't forget to update the *.pyc files (cxx/skel/template.pyc) if you've
installed omniidl somewhere)
Greetings,
--
Jeroen Dobbelaere
Software Design Engineer
Micro-Matic Research <http://www.mmr.be>
<<patch3.patch>>
------_=_NextPart_000_01C01F28.6E1E57A0
Content-Type: application/octet-stream;
name="patch3.patch"
Content-Disposition: attachment;
filename="patch3.patch"
*** omni/include/OmniORB3/CORBA.h Fri Aug 18 15:09:20 2000
--- omni_test/include/OmniORB3/CORBA.h Fri Sep 15 15:08:37 2000
***************
*** 1397,1406 ****
--- 1397,1449 ----
void operator>>=(MemBufferedStream&) const;
void operator<<=(MemBufferedStream&);
size_t _NP_alignedSize(size_t) const;
};
+ //////////////////////////////////////////////////////////////////////
+ /////////////////// Registration of static objects ///////////////////
+ //////////////////////////////////////////////////////////////////////
+
+ class _CleanUpObject_Base
+ {
+ public:
+ _CleanUpObject_Base() {}
+ virtual ~_CleanUpObject_Base() { };
+ };
+
+ template <typename T>
+ class _CleanUpObject : public _CleanUpObject_Base
+ {
+ public:
+ _CleanUpObject(T* tmp) : m_object(tmp) {}
+ virtual ~_CleanUpObject() { delete m_object; }
+
+ private:
+ T* m_object;
+ };
+
+ extern void _register_cleanupobject_for_autodestruction(_CleanUpObject_Base*);
+
+ // Function Template to register a CORBA::Object for auto destruction
+ template <typename T>
+ T* _register_corba_object_for_autodestruction(T* obj)
+ {
+ _CleanUpObject_Base* tmp = new _CleanUpObject<CORBA::Object>(obj);
+ _register_cleanupobject_for_autodestruction(tmp);
+
+ return obj;
+ }
+
+ // Function Template to register an object for auto destruction
+ template <typename T>
+ T* _register_other_object_for_autodestruction(T* obj)
+ {
+ _CleanUpObject_Base* tmp = new _CleanUpObject<T>(obj);
+ _register_cleanupobject_for_autodestruction(tmp);
+
+ return obj;
+ }
#ifdef HAS_Cplusplus_Namespace
_CORBA_MODULE_END
_CORBA_MODULE CORBA
*** omni/src/lib/OmniORB2/omniidl_be/cxx/skel/template.py Fri Aug 18 15:09:14 2000
--- omni_test/src/lib/OmniORB2/omniidl_be/cxx/skel/template.py Fri Sep 15 15:10:44 2000
***************
*** 145,155 ****
@name@::_nil()
{
static @objref_name@* _the_nil_ptr = 0;
if( !_the_nil_ptr ) {
omni::nilRefLock().lock();
! if( !_the_nil_ptr ) _the_nil_ptr = new @objref_name@;
omni::nilRefLock().unlock();
}
return _the_nil_ptr;
}
--- 145,155 ----
@name@::_nil()
{
static @objref_name@* _the_nil_ptr = 0;
if( !_the_nil_ptr ) {
omni::nilRefLock().lock();
! if( !_the_nil_ptr ) _the_nil_ptr = CORBA::_register_corba_object_for_autodestruction(new @objref_name@);
omni::nilRefLock().unlock();
}
return _the_nil_ptr;
}
*** omni/src/lib/OmniORB2/orbcore/omniInternal.cc Fri Aug 18 15:09:12 2000
--- omni_test/src/lib/OmniORB2/orbcore/omniInternal.cc Fri Sep 15 15:13:39 2000
***************
*** 1040,1044 ****
--- 1040,1083 ----
// static initialisation.
omni::nilRefLock();
}
static static_initialiser the_instance;
};
+
+
+ // track other static objects, for destruction afterwards
+ #include <list>
+
+ namespace CORBA
+ {
+ // registering function for static objects
+ class TrackCleanUpObjects
+ {
+ public:
+ typedef std::list<CORBA::_CleanUpObject_Base*> Container;
+ public:
+ TrackCleanUpObjects() {}
+ ~TrackCleanUpObjects() { delete_all(); }
+
+ void attach(CORBA::_CleanUpObject_Base* rhs) { m_table.push_back(rhs); }
+
+ void delete_all()
+ {
+ for(Container::reverse_iterator it=m_table.rbegin(); it != m_table.rend(); ++it)
+ {
+ delete *it;
+ }
+
+ m_table.erase(m_table.begin(), m_table.end());
+ }
+
+ private:
+ Container m_table;
+ };
+
+ void _register_cleanupobject_for_autodestruction(_CleanUpObject_Base* obj)
+ {
+ static TrackCleanUpObjects local_trackOtherObjects;
+
+ local_trackOtherObjects.attach(obj);
+ }
+ }
------_=_NextPart_000_01C01F28.6E1E57A0--