# Memory Leak and MultiThreading Problem in TRORttiClientCache.GetCustomAttributes

**URL:** https://talk.remobjects.com/t/memory-leak-and-multithreading-problem-in-trortticlientcache-getcustomattributes/18769
**Category:** Remoting SDK
**Tags:** delphi, rttisupport
**Created:** [February 20, 2019, 6:29am UTC](https://talk.remobjects.com/t/memory-leak-and-multithreading-problem-in-trortticlientcache-getcustomattributes/18769 "2019-02-20T06:29:50Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![apustotin](https://talk.remobjects.com/user_avatar/talk.remobjects.com/apustotin/32/5912_2.png) [@apustotin](https://talk.remobjects.com/u/apustotin)
#### Post date: [February 20, 2019, 6:29am UTC](https://talk.remobjects.com/t/memory-leak-and-multithreading-problem-in-trortticlientcache-getcustomattributes/18769/1 "2019-02-20T06:29:51Z")

</div>

Hi

I use RO SDK

```auto
const
  RO_VERSION = '9.5.111.1399';

```

We found two problems in TRORttiClientCache.GetCustomAttributes:

- memory leak
- non-threadsafe code

This is a proposed fix:

```
function TRORttiClientCache.GetCustomAttributes(aObject: TRttiObject): TDictionary<String, String>;
var
  la : TArray<ROCustomAttribute>;
  a: ROCustomAttribute;
begin
  BeginRead;
  try
    if fCustomAttributes.TryGetValue(aObject, result) then
      Exit;
    BeginWrite;
    try
      if not fCustomAttributes.TryGetValue(aObject, result) then begin
        Result := CreateDict<String>;
        la := aObject.ROGetAttributes<ROCustomAttribute>;
        for a in la do
          Result.Add(LowerCase(a.Name), a.Value);
        fCustomAttributes.Add(aObject, result); // <- fixing the leak
      end;
    finally
      EndWrite;
    end;
  finally
    EndRead;
  end;
end;

```

regards

---

<div class="post-metadata">

### Author: ![RemObjectsSoftware](https://talk.remobjects.com/user_avatar/talk.remobjects.com/remobjectssoftware/32/15947_2.png) [@RemObjectsSoftware](https://talk.remobjects.com/u/RemObjectsSoftware)
#### Post date: [February 20, 2019, 8:27am UTC](https://talk.remobjects.com/t/memory-leak-and-multithreading-problem-in-trortticlientcache-getcustomattributes/18769/2 "2019-02-20T08:27:33Z")

</div>

Thanks, logged as bugs://82003

---

<div class="post-metadata">

### Author: ![RemObjectsSoftware](https://talk.remobjects.com/user_avatar/talk.remobjects.com/remobjectssoftware/32/15947_2.png) [@RemObjectsSoftware](https://talk.remobjects.com/u/RemObjectsSoftware)
#### Post date: [February 20, 2019, 8:54am UTC](https://talk.remobjects.com/t/memory-leak-and-multithreading-problem-in-trortticlientcache-getcustomattributes/18769/3 "2019-02-20T08:54:02Z")

</div>

bugs://82003 got closed with status fixed.

---

<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: [February 20, 2019, 8:54am UTC](https://talk.remobjects.com/t/memory-leak-and-multithreading-problem-in-trortticlientcache-getcustomattributes/18769/4 "2019-02-20T08:54:58Z")

</div>

this fix will be included into next beta
