QLXL possible memory leak revisited

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

QLXL possible memory leak revisited

Peter Caspers-2
Hi Eric, Ferdinando, Luigi, all,

some months ago there were discussions about a possible memory leak in QLXL 1.1, in fact I found two related threads

http://old.nabble.com/qlxl-dependencies-and-object-updates-td30925399.html
http://old.nabble.com/possible-memory-leak-in-quantlib-addin-td29510169.html

I guess the reason for the observation of increasing memory usage when doing recalculations of excel sheets is the multiple registration of observables on the level of ObjectWrapper in the object handler. I just inserted a line that unregisters all observables before registering the precendet objects, i.e.

diff --git a/ObjectHandler/oh/repository.cpp b/ObjectHandler/oh/repository.cpp
index 49e8b76..563b4e1 100644
--- a/ObjectHandler/oh/repository.cpp
+++ b/ObjectHandler/oh/repository.cpp
@@ -109,6 +109,8 @@ namespace ObjectHandler {
     void Repository::registerObserver(
         boost::shared_ptr<ObjectWrapper> objWrapper){

+            objWrapper->unregisterAllWith();
+

             const std::set<std::string>& relationObs = objWrapper->object()->properties()->getPrecedentObjects();
             std::set<std::string>::const_iterator iter = relationObs.begin();
             for(; iter != relationObs.end();  iter++){


and thereby fixing the problem as can be tested e.g. in Ferdinandos test sheet attached to one of the old postings (book2.xls, running the macro calc_forever).

I think one can also constrain the call of registerObserver to the case of newly created ObjectWrapper instances and explicitly overwritten ones, i.e. in addition to the above change one could write

diff --git a/ObjectHandler/ohxl/repositoryxl.cpp b/ObjectHandler/ohxl/repositoryxl.cpp
index 54dbfd0..31e8d9c 100644
--- a/ObjectHandler/ohxl/repositoryxl.cpp
+++ b/ObjectHandler/ohxl/repositoryxl.cpp
@@ -79,6 +79,7 @@ namespace ObjectHandler {
                     new ObjectWrapperXL(objectID, object, callingRange));
                 objectMap_[objectID] = objectWrapperXL;
                 callingRange->registerObject(objectID, objectWrapperXL);
+                registerObserver(objectWrapperXL);
             } else {
                 objectWrapperXL = boost::static_pointer_cast<ObjectWrapperXL>(result->second);
                 if (objectWrapperXL->callerKey() != callingRange->key()) {
@@ -88,11 +89,11 @@ namespace ObjectHandler {
                         objectWrapperXL->callerAddress());
                     objectWrapperXL->resetCaller(callingRange);
                     callingRange->registerObject(objectID, objectWrapperXL);
+                    registerObserver(objectWrapperXL);
                 }
                 objectWrapperXL->reset(object);
             }
-
-            registerObserver(objectWrapperXL);


             return objectWrapperXL->idFull();
     }


and get the same result with even slightly improved efficiency.

I also noted that the observer / observable pattern code is duplicated in the object handler (objecthandler/oh/observable.hpp). In QL 1.2 the storage of observers and observables was changed from std::list to std::set. I believe that this would also help in the context above, yet not fully resolve the problem. Anyway, the improved code should be moved to the object handler, too, yes? Is there by the way a special reason for duplicating the code? Is it to keep the object handler independent of QL in some sense?

Thank you
Peter

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev

Book2.xls (41K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: QLXL possible memory leak revisited

Eric Ehlers-2
Hi Peter,

Quoting Peter Caspers <[hidden email]>:

> Hi Eric, Ferdinando, Luigi, all,
>
> some months ago there were discussions about a possible memory leak  
> in QLXL 1.1,

Thanks for the patches you supplied.  If I understand correctly, a  
subset of that patch was applied to the repository and this resolved  
some of the problems with the memory leaks.  Please get back to us if  
you need clarification.

> I also noted that the observer / observable pattern code is  
> duplicated in the object handler (objecthandler/oh/observable.hpp).  
> In QL 1.2 the storage of observers and observables was changed from  
> std::list to std::set. I believe that this would also help in the  
> context above, yet not fully resolve the problem. Anyway, the  
> improved code should be moved to the object handler, too, yes? Is  
> there by the way a special reason for duplicating the code? Is it to  
> keep the object handler independent of QL in some sense?

ObjectHandler has no dependency on QuantLib.  There would be nothing  
preventing us from copying the new improved observable.hpp from  
QuantLib to ObjectHandler.

Regards,
Eric

===================================================
Eric Ehlers
nazcatech sprl | Brussels | http://www.nazcatech.be
* Distributed computing for pricing analytics
* Use Microsoft Excel as a client to the Grid


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev