# Returning a complex type

**URL:** https://talk.remobjects.com/t/returning-a-complex-type/30791
**Category:** Remoting SDK
**Tags:** delphi
**Created:** [September 15, 2024, 5:18pm UTC](https://talk.remobjects.com/t/returning-a-complex-type/30791 "2024-09-15T17:18:15Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Jorge\_Ortiz\_Zurita](https://talk.remobjects.com/user_avatar/talk.remobjects.com/jorge_ortiz_zurita/32/18254_2.png) [@Jorge\_Ortiz\_Zurita](https://talk.remobjects.com/u/Jorge_Ortiz_Zurita)
#### Post date: [September 15, 2024, 5:18pm UTC](https://talk.remobjects.com/t/returning-a-complex-type/30791/1 "2024-09-15T17:18:16Z")

</div>

Hello, I have a question.

It is correct this implementation for a complex type named tcliente

I am doing some testing with complex types, and I want to understand it all before doing it in production.

I have this type:

```delphi
tcliente = class(TROComplexType)
  private
    fnombre: string;
    fapellido: String;
    fsueldo: double;
  published
    property nombre :string read fnombre write fnombre;
    property apellido : String read fapellido write fapellido;
    property sueldo: double read fsueldo write fsueldo;
  end;

```

and this is the implementation for one test function.

```delphi
    [ROServiceMethod]
    function saludacliente(cliente:string):tcliente;

function TTestService.saludacliente(cliente: string): tcliente;
var resp:tcliente;
begin
  resp:=tcliente.Create;
  resp.nombre:='Hola '+cliente+' nombre';
  resp.apellido:='Adios '+cliente+' apellido';
  resp.sueldo:=5000;
  Result:=resp;
  //resp.Free;
end;

```

If i tried resp.free i got exceptions when calling the function; if not, it runs correctly.

Is it okay not to do resp.free?

There is going to be a memory leak in the server if you don’t do it?

If I have to do it, what is the proper way?

As always, thanks for your advice.

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [September 16, 2024, 6:10am UTC](https://talk.remobjects.com/t/returning-a-complex-type/30791/2 "2024-09-16T06:10:20Z")

</div>

Hi,

I suggest to read the [Remote Object Allocation and Serialization (Delphi)](https://docs.remotingsdk.com/Servers/Technologies/ObjectAllocation_Delphi/) article.

in brief:

> Here is the rule of thumb: _ **Always free the memory on the client and never free it on the server** _.

---

<div class="post-metadata">

### Author: ![Jorge\_Ortiz\_Zurita](https://talk.remobjects.com/user_avatar/talk.remobjects.com/jorge_ortiz_zurita/32/18254_2.png) [@Jorge\_Ortiz\_Zurita](https://talk.remobjects.com/u/Jorge_Ortiz_Zurita)
#### Post date: [September 16, 2024, 11:01pm UTC](https://talk.remobjects.com/t/returning-a-complex-type/30791/3 "2024-09-16T23:01:31Z")

</div>

Thanks!  
I will follow your advice.
