XData destroys all objects serialized in the response. Thus, it will indeed destroy both TLoginResult
instance and the TLoginUser
instance, so you are fine.
If you want to keep the User
lifetime to be managed by the TLoginResult
object, you can set the following property in your Login
implementation:
TXDataOperationContext.Current.Handler.ActionResultDestruction := TActionResultDestruction.RootOnly;
This way, only the root object (TLoginResult
) will be destroyed, and it will be up to you (or the root object) to destroy other objects. This was also discussed here: access violation in simultaneous request of the same resource using service. - #3 by wlandgraf.