DataSnap(rest/json),Add new Object To Deserializer

Hi, Wagner
  I using "Distributed Applications" with DataSnap(rest/json)+aurelius.
when call a server method, "GetAll", the result  is a TList<TSomeObject>, then "Deserialize.OwnsEntities := True" and Deserialize.FromJson<T>(Value), later when Deserialize,DisposeOf, TList<TSomeObject> is destroy, until now everything works great.
  Now, i need to add a Object to TList<TSomeObject>, when "Deserialize,DisposeOf" the result from the server is destroyed, but the new object created is not destroy, because the new object is not "attached" to the deserializer.
  How to add a new Object to the deserializer for later destroy on "Deserializer.DisposeOf;"?
  Same issue with Master-Detail, when add a Object to the detail.
Thanks,
 

 

 
 


 

Unfortunately, you can't. You would have to manage the extra objects yourself, you can just put them in a separate list, for example.

Hi, again
 Its the same for AureliusDataset?
thanks

AureliusDataset creates objects on Insert, and add them to the list on Post. Yes, it's up to the list, or object manager (if you put the object there) to destroy the object.

Hi
"Yes, it's up to the list, or object manager (if you put the object there) to destroy the object."
Object Manager?!!! on client side?
  Sorry but something is missing,  what is the plan to avoid memory leaks on client side?
Many thanks

I'm just talking about AureliusDataset itself. It allows an object manager to be attached to the dataset, it's up to you to use it or not. You could use SQLite on client side as an alternative, but that's just one option.

If you don't have any manager because you are using Datasnap only on client side, then you have to manage it yourself. How would you do it if you are not using Aurelius? 

Maybe i could use some kind of factory pattern, for new objects and "Deserialize.OwnsEntities := True" and "Deserialize,DisposeOf" for Deserialize attached objects, this makes sense?
Thanks


I don't know how you create your objects. What are the difficulties you are having with the current approach? It should not be complicated the way it is, but maybe there is some added complexity in your application?

If you create the object yourself, just add to a list and destroy the objects in the list later.
You can also set OwnsObjects := false and manage all objects yourself, if it's easier. The deserializer gives you a list of objects it created (Entities) and also an event OnEntityCreated in case you want to add the object to a list when it's created by the deserializer.