On 19/01/2010 19:03, Mathias Bauer wrote: > Matthias B. wrote: > >> I have a component that registers on the GlobalEventBroadcaster to >> listen for new documents (OnCreate event) to do some processing on >> every text document that is opened. Now I have the problem that >> OpenOffice.org broadcasts these events even for internal documents >> that it creates temporarily. For instance when I insert an AutoText, >> OOo apparently creates a text document in the background and >> broadcasts and OnCreate event for it. When doing a MailMerge it >> creates lots of these background documents. >> >> This creates all kinds of trouble. For instance these documents are >> quickly disposed which causes DisposedExceptions in my component and >> while my component catches these and can deal with the situation, OOo >> becomes unstable and eventually crashes or freezes when this happens >> too often during mail merge. > > You should catch these exceptions or register as a Listener and get > notified when the document is disposed. As the DevGuide says, every code > that stores references to objects implementing XComponent (like > documents) not only temporarily (means: on the stack) must do either of > these. A third option is to use a WeakReference instead of a "hard" one > and always try to make it "hard" before using it.
i am not sure if a WeakReference would really help here... i guess it depends. in same-process C++ it should work. in a garbage-collected environment (like java) the hard reference that is necessary to create the weak reference may well live on after the instance it points to is disposed, so you can probably convert the WeakReference to a hard reference to a disposed instance in this case. when catching exceptions, you should catch uno::RuntimeException, and not DisposedException; at least in the writer implementation there are lots of places where a bare RuntimeException is thrown when accessing a disposed object. (i guess that should be fixed...) listeners should work. regards, michael -- "The demand for certainty is one which is natural to man, but is nevertheless an intellectual vice." -- Bertrand Russell --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
