Jump to content
Sign in to follow this  
Rainer Wolff

spring4d list immidiately gets freed

Recommended Posts


i have the following lines:

class function TToollist.GetItemById(Index: Integer): TTool;
  result := nil;
  for w in Toollist do
    if w.oid = Index then
      result := w;

class function TToollist.GetToollist: IList<TTool>;
  if not Assigned(FToollist) then
//    FToollist:=dm.Session.FindAll<TTool>;

My property Toollist is touched for the first time by fetching an Item by Id, the getter finds FToollist not yet assigned, creates it and reads its data from database, using spring4d orm.

I want the Items to be in an Observable list, so loading db and then adding to the List.


But as soon as I leave the getter, my FToollist is freed via interface reference count and all my items are released.


If I just load my items directly into the FToollist, as in the commented line instead of using CreateObservableList and adding range, everything is fine.


My FToollist is a IList<TTool> in both cases.


I'd like to learn the internals of this behaviour, can someone explain it to me?



Share this post

Link to post
Posted (edited)

FToollist is certainly not being freed but the items because the list returned by FindAll has OwnsObjects = True and goes out of scope at the end of the method.

Write dm.Session.FindAll<TTool>.MoveTo(FToolllist);

Edited by Stefan Glienke

Share this post

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this