[prev in list] [next in list] [prev in thread] [next in thread]
List: koffice
Subject: klibloader
From: Simon Hausmann <shaus () uermel ! Med ! Uni-Magdeburg ! DE>
Date: 1999-10-27 16:27:22
[Download RAW message or body]
Hi!
We store components in shared libraries. Loading them is fine, but we also
have to pay attention to *unloading* them properly when they are not
needed anymore.
I just implemented the necessary mechanism in klibloader. However
KLibLoader can't do all the magic, the application/component progammer
still has to do some things manually :-) , in order to avoid horrible
memory leaks.
So please make sure your koffice application implements/handles the
following things:
- Somewhere in your code you inherit from KLibFactory. In there you
re-implement one create() method, in which you allocate new KOffice
document objects. KLibLoader *has* to know about all objects created in
your factory, so please change your create method to something like
this:
...
MyDocument *foo = new BarDoc;
emit objectCreated( foo );
return foo;
The important thing is emitting the objectCreated() signal.
- In addition your KOffice component allocates a KInstance object
somewhere (usually this is in your factory class, too) .
When a shared library gets unloaded, your factory object gets deleted,
too, so please make sure that you delete all objects, in the destructor
of your factory class, which you allocated *beside* the ones allocated
in your create() method. Usually this is just a KInstance object.
The general approach of how to determine if a shared library is not used
(referenced) anymore is to check if all objects created via the
KLibFactory::create() method have been destroyed (this is done by
connecting to the destroyed() signal of QObject) . This provides you the
comfortable feature that you will never have to call
KLibLoader::self()->unloadLibrary() or so. Just delete the object and
KLibLoader does the rest: It checks if there are any other objects left,
and if none, then it launches a timer. After a timeout of one minute it
will unload (close) the library (and delete the KLibFactory object
before) .
Ciao,
Simon (...being lazy by trying to choose this way of explaining the
stuff instead of patching/fixing KOffice :-)
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic