You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Thank you for pointing out this error in the documentation. That's because we usually do a static import on Scope.Singleton. I updated the documentation in that respect.
Regarding your other problem, it's related to the singleton scope, as stated in the documentation :
If your bean has a Singleton scope, it will only keep a reference to the application context (using context.getApplicationContext(). That's because it leaves longer then any activity / service, so it shouldn't keep a reference to any such Android component, to avoid leaks.
We also skip view injection in that case, because views usually contain references to the activity, so that would also lead to a memory leak. This problem was also pointed out in #186.
What do you need a singleton for? What's your use case?
If I answered your questions, please do not hesitate to close the issue :) .
We also disable view injection and view event binding in @EBean components with Singleton scope, for the exact same reason (views have a reference to the activity, which may therefore create a leak).
Each of my activity has its own ActivityNameViewHolder for holding all view components of an activity. So I want to set this ActivityNameViewHolder as singleton to access it from different classes without recreating it or holding somewhere else
I see :) . The singleton pattern is for components that live as long as the app live. This doesn't fit your use case. What you actually need is an Activity scope. We don't provide that for now, but we probably should :) .
Activity
pyricau commentedon May 19, 2012
Hi @pleerock,
Thank you for pointing out this error in the documentation. That's because we usually do a static import on
Scope.Singleton. I updated the documentation in that respect.Regarding your other problem, it's related to the singleton scope, as stated in the documentation :
We also skip view injection in that case, because views usually contain references to the activity, so that would also lead to a memory leak. This problem was also pointed out in #186.
What do you need a singleton for? What's your use case?
If I answered your questions, please do not hesitate to close the issue :) .
pyricau commentedon May 19, 2012
I updated the documentation with more details:
pleerock commentedon May 19, 2012
Each of my activity has its own ActivityNameViewHolder for holding all view components of an activity. So I want to set this ActivityNameViewHolder as singleton to access it from different classes without recreating it or holding somewhere else
pyricau commentedon May 20, 2012
I see :) . The singleton pattern is for components that live as long as the app live. This doesn't fit your use case. What you actually need is an
Activityscope. We don't provide that for now, but we probably should :) .