EntityCachingMode StrongReference vs WeakReference

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
-marcelo-
Posts: 26
Joined: Wed 28 Jun 2017 12:35

EntityCachingMode StrongReference vs WeakReference

Post by -marcelo- » Sun 14 Oct 2018 22:21

Long story short, for application n-tier convenience, I´m deriving all entities in my model from an EntityBase class (of my own, of course).
Once finished a query in the form of List<Entity> I pass it to EntityBase method

Code: Select all

        protected BindingList<EntityBase> upCast<T>(List<T> source) where T : EntityBase
        {
            BindingList<EntityBase> result = new BindingList<EntityBase>() { AllowEdit = true, AllowNew = true, AllowRemove = true, RaiseListChangedEvents = true };
            foreach (T t in source)
                result.Add(t as EntityBase);
            return result;
        }
So, the original references to Entity en List<Entity> are added to a BindingList<EntityBase> result.

It seems to me that all of them are referenced because, in fact, the binding list is populated with references to evey Entity.
In other words; they could not be garbage collected, so I can go with the default of WeakReference.
Is that true?
TIA

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: EntityCachingMode StrongReference vs WeakReference

Post by Shalex » Thu 18 Oct 2018 12:48

That is true.

Post Reply