# Memory leak when executing remote command from the client

**URL:** https://talk.remobjects.com/t/memory-leak-when-executing-remote-command-from-the-client/3797
**Category:** Data Abstract
**Created:** [February 24, 2014, 12:21pm UTC](https://talk.remobjects.com/t/memory-leak-when-executing-remote-command-from-the-client/3797 "2014-02-24T12:21:59Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![CorumJI](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@CorumJI](https://talk.remobjects.com/u/CorumJI)
#### Post date: [February 24, 2014, 12:21pm UTC](https://talk.remobjects.com/t/memory-leak-when-executing-remote-command-from-the-client/3797/1 "2014-02-24T12:21:59Z")

</div>

Hi there,

using Delphi XE5, I always have the “ReportMemoryLeaksOnShutdown” option set to true in debug mode.  
When executing the following code,

```
function TServiceRegister.Application: Integer;
var
  lArr : DataParameterArray;
  rc : TDARemoteCommand;
 begin
  result := -1;

  rc := GetRemoteCommand;
  rc.Execute('RegisterApplication', ['name', 'id_application'], ['Test', result]);
   lArr := DataParameterArray(rc.ExecuteCall.Params.FindParam(rc.ExecuteCall.IncomingParametersParameter).AsComplexType);
  result := DataParameter(lArr.Search('Name', 'id_application')).Value;
end;

```

I get the following memory leak when closing the application :

![](https://talk.remobjects.com/uploads/default/188/912e2b50dc670622.png)

Being definitely new to RemObjects and DataAbstract, I guess that maybe I am doing things wrong and there is a better (simpler) way to achieve this trivial task…  
However, I have to admit that everything works as expected and the remote command is executed! 🙂

Could somebody point me to the right direction?  
Thanks in advance.

Kind regards,

Charles

---

<div class="post-metadata">

### Author: ![vovanl](https://talk.remobjects.com/user_avatar/talk.remobjects.com/vovanl/32/51_2.png) [@vovanl](https://talk.remobjects.com/u/vovanl)
#### Post date: [February 25, 2014, 2:52pm UTC](https://talk.remobjects.com/t/memory-leak-when-executing-remote-command-from-the-client/3797/2 "2014-02-25T14:52:54Z")

</div>

Hello,  
Please free lArr variable:

```
lArr := DataParameterArray(rc.ExecuteCall.Params.FindParam(rc.ExecuteCall.IncomingParametersParameter).AsComplexType);
result := DataParameter(lArr.Search('Name', 'id_application')).Value;
lArr.Free;
```

---

<div class="post-metadata">

### Author: ![CorumJI](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@CorumJI](https://talk.remobjects.com/u/CorumJI)
#### Post date: [February 25, 2014, 4:43pm UTC](https://talk.remobjects.com/t/memory-leak-when-executing-remote-command-from-the-client/3797/3 "2014-02-25T16:43:05Z")

</div>

Hi Vovan,

Problem is that I had one single remote command on a data module and freeing the data parameters array was no good idea at all (worked perfectly once than crashed at the next call! 😄).  
However, I now implemented a factory class that returns a remote command on demand and updated my code.  
Now freeing the array and the remote command works fine, no memory leaks anymore.  
Thanks for your help.

Kind regards,

Charles
