# Memory leak while using OPC UA Server

**URL:** <https://forum.inductiveautomation.com/t/memory-leak-while-using-opc-ua-server/19733>\
**Category:** Ignition\
**Created:** [September 19, 2018, 1:33pm UTC](https://forum.inductiveautomation.com/t/memory-leak-while-using-opc-ua-server/19733 "2018-09-19T13:33:23Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![antoni.g](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@antoni.g](https://forum.inductiveautomation.com/u/antoni.g)\
**Post date:** [September 19, 2018, 1:33pm UTC](https://forum.inductiveautomation.com/t/memory-leak-while-using-opc-ua-server/19733/1 "2018-09-19T13:33:23Z")

</div>

Hi,

We have OPC UA server with an integer tag .  
We could connect to the OPC Server using Ignition.  
We have timer based client script firing every 10 ms to write to the integer tag with value of 50 as shown below  
system.tag.write(“IntegerItem”,50)

We could see the memory growth for every write.  
We have observed the traffic using Wireshark . We could see for every OPC UA write there is a OPC UA read is performed .

We suspect this additional OPC UA Read may cause the memory increase.

Could you please help us why there is additional OPC UA Read while using Ignition?

Thanks  
Antoni

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 19, 2018, 3:51pm UTC](https://forum.inductiveautomation.com/t/memory-leak-while-using-opc-ua-server/19733/2 "2018-09-19T15:51:55Z")

</div>

The Read asks the server for the DataType, ValueRank, and ArrayDimension attributes so the Ignition client can be sure to send a value with the correct DataType in the Write. Unfortunately this information is not cached anywhere right now, so it happens for every write as you’re seeing.

---

<div class="post-metadata">

**Author:** ![gkalipershad](https://avatars.discourse-cdn.com/v4/letter/g/dc4da7/32.png) [@gkalipershad](https://forum.inductiveautomation.com/u/gkalipershad)\
**Post date:** [September 20, 2018, 7:14pm UTC](https://forum.inductiveautomation.com/t/memory-leak-while-using-opc-ua-server/19733/3 "2018-09-20T19:14:58Z")

</div>

Hi Kevin,

I have been working with Antoni on this. You mentioned that “this information is not cached anywhere right now”. Can we expect this to be added in Version 8? Is that still expected to be released in Q1 of 2019?

Thanks,  
Ganesh

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 20, 2018, 7:21pm UTC](https://forum.inductiveautomation.com/t/memory-leak-while-using-opc-ua-server/19733/4 "2018-09-20T19:21:35Z")

</div>

I’m not sure this will be added for 8 or not. It’s low priority because it shouldn’t really matter.

The current release date target is February 2019.

---

<div class="post-metadata">

**Author:** ![antoni.g](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@antoni.g](https://forum.inductiveautomation.com/u/antoni.g)\
**Post date:** [September 21, 2018, 3:44pm UTC](https://forum.inductiveautomation.com/t/memory-leak-while-using-opc-ua-server/19733/5 "2018-09-21T15:44:51Z")

</div>

HI Kevin,  
We appreciate your quick reply on this. Thank you.

We suspect that the memory leak is because of not caching the information by ignition.

We have tried with another OPC UA client “OPC Labs Data client” , we do not see any memory leak in our OPC Server.

Is it safe to assume the memory leak is because of this behavior? Please advise.

NOTE : Our OPC server is developed using VB .NET .

Thank you again

Regards  
Antoni

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 21, 2018, 4:01pm UTC](https://forum.inductiveautomation.com/t/memory-leak-while-using-opc-ua-server/19733/6 "2018-09-21T16:01:32Z")

</div>

> [@antoni.g](#):
>
> Is it safe to assume the memory leak is because of this behavior? Please advise.

It's possible, but my point is that reading those values repeatedly shouldn't cause a memory leak in your OPC server. If it does, that's a problem you need to fix, not us.

---

<div class="post-metadata">

**Author:** ![antoni.g](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@antoni.g](https://forum.inductiveautomation.com/u/antoni.g)\
**Post date:** [September 25, 2018, 3:00pm UTC](https://forum.inductiveautomation.com/t/memory-leak-while-using-opc-ua-server/19733/7 "2018-09-25T15:00:59Z")

</div>

Hi Kevin,  
Thanks for the reply .

Basically we use COM object inside our .NET application. In our case the OPC UA tag is a COM object which is referred by Ignition script always and never get released.  
Is there anyway to release the COM referred object to read/write from python script?

Thanks  
Antoni

---

<div class="post-metadata">

**Author:** ![prakash.vs](https://avatars.discourse-cdn.com/v4/letter/p/a9adbd/32.png) [@prakash.vs](https://forum.inductiveautomation.com/u/prakash.vs)\
**Post date:** [September 27, 2018, 4:22am UTC](https://forum.inductiveautomation.com/t/memory-leak-while-using-opc-ua-server/19733/8 "2018-09-27T04:22:39Z")

</div>

Hi Kevin  
I could not get any response for memory leak issue introduced by ignition software when I have connected COM type server to it.  
When the opc tags are referred then the reference for COM object is auto incremented. The memory for COM object are released only when the reference count to COM Memory Object is zero. The ignation software these references are incremented but never get released so memory can not be collected by garbage collected. This memory can be released using  
" System.Runtime.InteropServices.Marshal.ReleaseComObject(COMObject);  
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(COMObject);" in ignition side software.  
When these tags(COM\_) objects are referred in the c# side application we are using these statements to release reference. but still one reference is pending which is hold by ignition software., hence associate memory is not collected and memory leaks.  
I request to do the necessary action and reply ASAP to make the ignition compatible to all type of server like COM servers.

Thanks ., Awaiting reply ASAP.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 27, 2018, 4:00pm UTC](https://forum.inductiveautomation.com/t/memory-leak-while-using-opc-ua-server/19733/9 "2018-09-27T16:00:15Z")

</div>

Are you still talking about an OPC UA connection from Ignition or are you talking about an OPC COM/Classic connection now?

---

<div class="post-metadata">

**Author:** ![prakash.vs](https://avatars.discourse-cdn.com/v4/letter/p/a9adbd/32.png) [@prakash.vs](https://forum.inductiveautomation.com/u/prakash.vs)\
**Post date:** [September 28, 2018, 3:48am UTC](https://forum.inductiveautomation.com/t/memory-leak-while-using-opc-ua-server/19733/10 "2018-09-28T03:48:12Z")

</div>

Yes. Thanks for reply, That issue is resolved from this side. When we do asynchronous write that happens. When we do synchronous write call that works fine as expected,. But still there is memory leak in even in synchronous write. For now I will further investigate server side application and get back to you on this, for any server c++ or COM server when we do write though Ignition, memory leak starts but when server side write calls no leak, what to do? Thanks for reply again.

---

<div class="post-metadata">

**Author:** ![prakash.vs](https://avatars.discourse-cdn.com/v4/letter/p/a9adbd/32.png) [@prakash.vs](https://forum.inductiveautomation.com/u/prakash.vs)\
**Post date:** [October 15, 2018, 6:58am UTC](https://forum.inductiveautomation.com/t/memory-leak-while-using-opc-ua-server/19733/11 "2018-10-15T06:58:31Z")

</div>

Hi  
I am talking about OPC UA connection to OPC COM server connection. When the values for tag is written by COM server., It allocates the memory for result array, Which should to be freed by ignition software after reading the result for each item using CoTaskMemFree(Results). If not freed the memory allocated by COM server will remain ,will cause memory leak. Please verify the same from Ignition side weather the return values are freed after writting ?  
Thanks for Help. Appreciating your response in advance.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [October 15, 2018, 1:16pm UTC](https://forum.inductiveautomation.com/t/memory-leak-while-using-opc-ua-server/19733/12 "2018-10-15T13:16:34Z")

</div>

> [@prakash.vs](#):
>
> When the values for tag is written by COM server., It allocates the memory for result array, Which should to be freed by ignition software after reading the result for each item using CoTaskMemFree(Results). If not freed the memory allocated by COM server will remain ,will cause memory leak.

That's not how OPC UA works. There's no shared memory and nothing for the OPC UA client to "free".

---

<div class="post-metadata">

**Author:** ![prakash.vs](https://avatars.discourse-cdn.com/v4/letter/p/a9adbd/32.png) [@prakash.vs](https://forum.inductiveautomation.com/u/prakash.vs)\
**Post date:** [October 16, 2018, 4:40am UTC](https://forum.inductiveautomation.com/t/memory-leak-while-using-opc-ua-server/19733/13 "2018-10-16T04:40:28Z")

</div>

Hi  
When you want to read.or wtite to tag the call is made to COM server? During this call a set of parameters are sent like result i.e. read success or write success to Ignition client. Once Ignition reads the result variable that needs to be freed?  
I hope this is correct if not correct me?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [October 16, 2018, 12:24pm UTC](https://forum.inductiveautomation.com/t/memory-leak-while-using-opc-ua-server/19733/14 "2018-10-16T12:24:35Z")

</div>

> [@prakash.vs](#):
>
> When you want to read.or wtite to tag the call is made to COM server?

You said this was on OPC UA connection, so the OPC UA Read and Write services are called. If there is an OPC COM server sitting behind it or involved in the implementation, that's transparent to Ignition.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 16, 2018, 12:39pm UTC](https://forum.inductiveautomation.com/t/memory-leak-while-using-opc-ua-server/19733/15 "2018-10-16T12:39:07Z")

</div>

> [@Kevin.Herron](#):
>
> that's transparent to Ignition

Unless it is Ignition's own OPC-COM module, in which case the entire discussion has been under the wrong title and assumptions.

---

<div class="post-metadata">

**Author:** ![prakash.vs](https://avatars.discourse-cdn.com/v4/letter/p/a9adbd/32.png) [@prakash.vs](https://forum.inductiveautomation.com/u/prakash.vs)\
**Post date:** [October 22, 2018, 1:48pm UTC](https://forum.inductiveautomation.com/t/memory-leak-while-using-opc-ua-server/19733/16 "2018-10-22T13:48:47Z")

</div>

Thanks Once again for the reply. Its very clear. Still I have one more doubt. When item values are written to COM server tag through Ignation, It is sending 3 times GetItemProperties and QueryAvailableProperties calls to COMserver for each write., whereas other Clients are not calling these functions at all. Its ok to send but the COM server is filling the BSTR string value to the properties of the tag, but I doubt whether client is clearing the BSTR memory after using that.

Thanks for all replies once again.

---

<div class="post-metadata">

**Author:** ![prakash.vs](https://avatars.discourse-cdn.com/v4/letter/p/a9adbd/32.png) [@prakash.vs](https://forum.inductiveautomation.com/u/prakash.vs)\
**Post date:** [October 23, 2018, 10:27am UTC](https://forum.inductiveautomation.com/t/memory-leak-while-using-opc-ua-server/19733/17 "2018-10-23T10:27:33Z")

</div>

hi  
Thanks for not replying. I got the answer myself. Since I have UA client other than Ignition which does not leak memory where as when I do the ignition as client leaks memory. I am investigating since 15 days. So I got some silly questions.  
Anyway Thanks again.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 23, 2018, 12:44pm UTC](https://forum.inductiveautomation.com/t/memory-leak-while-using-opc-ua-server/19733/18 "2018-10-23T12:44:02Z")

</div>

> [@prakash.vs](#):
>
> Thanks for not replying.

Snark doesn't help presenting your issue here. And you _ **were** _ answered. UA clients don't have access to a UA server's memory, so your memory leak _can only be your **own** problem_.

You keep mentioning "COM" objects, which _ **aren't used** _ in OPC/UA. If you have implemented the legacy OPC/DA protocol, which does use COM objects, there must be a "shim" between Ignition and your server. Such a shim _ **might be** _ contributing to your memory leak, but you haven't provided sufficient information about your setup to even identify whether this scenario applies.

If you cannot share more information in this public forum, consider contacting IA support to obtain professional help. Also consider climbing down from your high horse when asking for _ **free help** _ on a _ **user forum** _. I'm not a COM technology expert, but there are some on this forum, I believe.

---

<div class="post-metadata">

**Author:** ![prakash.vs](https://avatars.discourse-cdn.com/v4/letter/p/a9adbd/32.png) [@prakash.vs](https://forum.inductiveautomation.com/u/prakash.vs)\
**Post date:** [October 24, 2018, 3:51am UTC](https://forum.inductiveautomation.com/t/memory-leak-while-using-opc-ua-server/19733/19 "2018-10-24T03:51:48Z")

</div>

Thanks. Memory leak found in third party tool used in COM server used., Which none of the tool were detecting. So things are neutralized for now. I again appreciate your patience and help time to time Good bye.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [October 24, 2018, 5:13am UTC](https://forum.inductiveautomation.com/t/memory-leak-while-using-opc-ua-server/19733/20 "2018-10-24T05:13:10Z")

</div>

Glad you got it sorted out.
