openwebbeans-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lars-Fredrik Smedberg <itsme...@gmail.com>
Subject Re: Memleak using Instance<> with dependent
Date Fri, 27 Feb 2015 18:32:01 GMT
@Romain that is okay i guess as long as the produced value is not request
(perhaps on a per user basis) dependent... in that case i would like to
create it in the scope of the method called on the applicationscoped bean...

So I guess if I have this scenario I would need to either

1) do as u suggest by storing the value in the @postconstruct if it
possible (see above)

2) make the dependent object scoped

3) set another scope on the @ApplicationScoped  or @Singleton

Out of curiosity... when the value is for example a String or Locale which
is not subclassable...is owb holding on to the value somehow and prevent
them from being gc ed?

...or maybe i got it all wrong. ...
On Feb 27, 2015 7:26 PM, "Romain Manni-Bucau" <rmannibucau@gmail.com> wrote:

> When I used this pattern I always did (for perf reason but side effect is
>  behavior is what you want):
>
> @PostConstruct
> private void resolve() {
>    value = instance......get();
> }
>
> then in the code don't use instance at all but value.
>
>
>
> Romain Manni-Bucau
> @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> <http://rmannibucau.wordpress.com> | Github
> <https://github.com/rmannibucau> | LinkedIn
> <https://www.linkedin.com/in/rmannibucau>
>
> 2015-02-27 19:15 GMT+01:00 John D. Ament <john.d.ament@gmail.com>:
>
>> Are you calling get() on the Instance with each request (or whatever0
>> that comes into this bean?
>>
>> On Fri, Feb 27, 2015 at 1:13 PM Karl Kildén <karl.kilden@gmail.com>
>> wrote:
>>
>>> To explain myself further ALL I had on my heap was my
>>> Instance<MyInterface>... and gc released 0.5% memory :)
>>>
>>> I had 200 000 of them at least. They where supposed to be four
>>> singletons. My idea was inject into @ApplicationScoped and omit to give
>>> them scope because they will be @ApplicationScoped anyways... Seems every
>>> invocation of my @ApplicationScoped bean recreated all instances.
>>>
>>> What I had was unrecoverable mem leak. Now I could be doing something
>>> stupid or Instance<MyInterface> has a problem or something else...
>>>
>>> Cheers
>>>
>>>
>>>
>>> On 27 February 2015 at 19:05, Romain Manni-Bucau <rmannibucau@gmail.com>
>>> wrote:
>>>
>>>> If dependent it will be kept in enclosing bean.
>>>>  Le 27 févr. 2015 19:00, "Lars-Fredrik Smedberg" <itsmeden@gmail.com>
>>>> a écrit :
>>>>
>>>> So does this mean that there will be a memory leak in the case Karl
>>>>> described?
>>>>>
>>>>> I have used similar constructs before so im curios (@Inject @Provider
>>>>> <some dep scoped bean> in an @ApplicationScoped bean and called
get () on
>>>>> the injected provider).
>>>>>
>>>>> I thought for a while that it might get garbage collected when the
>>>>> created bean is outof scope or maybe then there is no way for @PreDestroy
>>>>> to be called?
>>>>>
>>>>> Regards
>>>>> LF
>>>>>
>>>>> I thought that the created dep scoped bean would be
>>>>> On Feb 27, 2015 6:07 PM, "Romain Manni-Bucau" <rmannibucau@gmail.com>
>>>>> wrote:
>>>>>
>>>>>> Yes.
>>>>>>
>>>>>> Will be destoyed with the bean where it is injected IIRC so the app
>>>>>> here.
>>>>>> Le 27 févr. 2015 16:59, <karl.kilden@gmail.com> a écrit :
>>>>>>
>>>>>>> Hello! I have a bean with @ApplicationScoped. When I inject
>>>>>>> Instance<MyInterface> instance and my actual beans implementing
MyInstance
>>>>>>> are dependentscoped they get recreated over and over and are
not gc'd.
>>>>>>>
>>>>>>> Expected behavior?
>>>>>>>
>>>>>>> Cheers
>>>>>>
>>>>>>
>>>
>

Mime
View raw message