Apache OpenOffice (AOO) Bugzilla – Issue 67511
Destructor of spell checker implementation is never called
Last modified: 2013-02-24 20:42:42 UTC
The destructor of an implementation of service `com.sun.star.linguistic2.SpellChecker' is never called. It seems to me that service `com.sun.star.linguistic2.LinguServiceManager' doesn't free all references to such an implementation at Strg-Q (or File -> Exit). I've written a small implementation to demonstrate the behaviour (see attachment). It is a patch based on the CppComponent example. You will get the following output after clicking Tools -> Options... -> Language Settings -> Writing Aids: $ /usr/lib/openoffice/program/swriter Increment reference count: 1 Increment reference count: 2 Decrement reference count: 2 Increment reference count: 2 Decrement reference count: 2 Increment reference count: 2 Decrement reference count: 2 Increment reference count: 2 Decrement reference count: 2 Increment reference count: 2 Decrement reference count: 2 Increment reference count: 2 Decrement reference count: 2 Increment reference count: 2 Decrement reference count: 2 Increment reference count: 2 Decrement reference count: 2 queryInterface Increment reference count: 2 com.sun.star.linguistic2.XSpellChecker Decrement reference count: 2 queryInterface Increment reference count: 2 com.sun.star.lang.XServiceInfo queryInterface Increment reference count: 3 com.sun.star.linguistic2.XSupportedLocales getLocales Decrement reference count: 3 Decrement reference count: 2 Decrement reference count: 1 dispose Increment reference count: 1 Increment reference count: 2 Decrement reference count: 2 disposing Decrement reference count: 1 ~MyService2Impl ----------------------------------------------- Increment reference count: 1 Increment reference count: 2 Decrement reference count: 2 Increment reference count: 2 Decrement reference count: 2 Increment reference count: 2 Decrement reference count: 2 Increment reference count: 2 Decrement reference count: 2 queryInterface Increment reference count: 2 com.sun.star.lang.XInitialization Decrement reference count: 2 Increment reference count: 2 Decrement reference count: 2 Increment reference count: 2 Decrement reference count: 2 Increment reference count: 2 Decrement reference count: 2 Increment reference count: 2 Decrement reference count: 2 queryInterface Increment reference count: 2 com.sun.star.linguistic2.XSpellChecker Increment reference count: 3 Decrement reference count: 3 Decrement reference count: 2 queryInterface Increment reference count: 2 com.sun.star.lang.XServiceDisplayName getServiceDisplayName getLocales Increment reference count: 3 Decrement reference count: 3 Clicking Cancel and Strg-Q doesn't decrement the reference counter and therefore the destructor was never called.
Created attachment 37869 [details] A simple spell checker test implementation
Created attachment 38244 [details] Update of the simple spell checker implementation.
Thomas, It seems this issue is not a Lingucomponent problem, isn't it?
TL: reassigned to me.
Some things to take note of: 1) spellcheckers (usually) are one-instance services. That is when they get created they live as long as the office (sometimes even longer!). 2) There can be cases where the d-tor does not get called. E.g. if in an external thread (e.g. by Java which has automatic garbage collection and thus may still keep references for some time) a reference to the spellchecker is still is use while the office is shut down. (In that case later on a the d-tor might be called for an alrteady dead object.) 3) This may also be the case because of some progamming error. E.g. if the component would be created with new and thus by-passing the service factory. This would result in the component being kept despite the reference count of the service factory going to 0. In general (and especially including the above) relying on tje d-tor being called to do to some required task is a bad choice anyway. For these purpose the spellchecker implements the XComponent interface. Any required clean-up, etc. should be done when dispose is called. Because of this I must admit I did not check the issue by using your patch but did only a quick check that 'dispose' gets called. This does happen. Thus unless there is anything more serious involved I'll retarget this one to 'OOo later'.
.
TL: I can also confirm that the d-tor does not get called.
TL->Laccy: Thus if the d-tor SpellChecker::~SpellChecker() in sspellimp.cxx really needs to execute it's code it should be moved. (If it is only about freeing memory that could be left to the OS. Even though it will be bad style there is no problem with it. That is: in this very case nothing bad will happen even if the d-tor does not get called.)
Nemeth->TL: It is all right for me. Thanks. Laci