|Re: @PreDestroy for singletons [message #1405530 is a reply to message #1405509]
||Thu, 07 August 2014 15:00
| Thomas Schindl
Registered: July 2009
@PreDestroy means that the CONTEXT to which the object was attached to|
I think the main problem is that @Createable creates an object on the
requesting context which is wrong for Singleton instances who should
most likely get created on the Root-Context and hence only haveing
access to the information in this root-context (==OSGi-ServiceRegistry)
I'm not a friend of this @Creatable all together and would advice to not
make use of it but better using IContextFunction and decide on what
level of the IEclipseContext the object is a singleton.
On 07.08.14 16:07, Uwe San wrote:
> I have an E4 application with two parts. Only one part is shown at a
> time, such that part one will be destroyed when part two is shown, and
> vice versa.
> Part one has a dependency to a Foo class which is injected into a
> @PostConstruct-annotated method in part one. The Foo class is annotated
> with @Creatable and @Singleton (as I want it to be a singleton).
> I tracked the lifecycle of the Foo instance by checking when its
> @PostConstruct- and @PreDestroy-annotated methods are called. The
> findings were surprising to me. Switching between parts one and two gave
> me the following results:
> Open part one:
> Foo - PostConstruct
> Open part two:
> Foo - PreDestroy
> Open part one again:
> Open part two again:
> So the Foo singleton instance is destroyed when part one is closed for
> the first time, but it is not constructed again when part one is opened
> for the second time. It must still exist since it is injected
> successfully into part one every time the part is constructed. But when
> the Foo instance still exists, how come the @PreDestroy method was called?
> Could it be that an object is not destroyed after the @PreDestroy method
> was called? My understanding is that "destroy" means the instance does
> not exist any more, but I may be wrong. According to the
> the object "is to be uninjected and released".
> I'd appreciate your feedback.
Powered by FUDForum
. Page generated in 0.01920 seconds