From 118857b6b4afb92db7eed9100ef58e30901576a4 Mon Sep 17 00:00:00 2001 From: hjhun <36876573+hjhun@users.noreply.github.com> Date: Fri, 20 Sep 2024 13:04:19 +0900 Subject: [PATCH] [Tizen.Core] Fix memory leak (#6336) The problem is that if the setter of ChannelObject's Data Property is called twice in a row, the previous data will not be removed. To prevent this, this patch is made it so that when the setter is called, the previous data is erased. Signed-off-by: Hwankyu Jhun --- src/Tizen.Core/Tizen.Core/ChannelObject.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Tizen.Core/Tizen.Core/ChannelObject.cs b/src/Tizen.Core/Tizen.Core/ChannelObject.cs index 98730fa1952..cc967effb7f 100644 --- a/src/Tizen.Core/Tizen.Core/ChannelObject.cs +++ b/src/Tizen.Core/Tizen.Core/ChannelObject.cs @@ -17,6 +17,7 @@ using System; using System.Collections.Concurrent; using System.Runtime.InteropServices; +using System.Security.Cryptography; namespace Tizen.Core { @@ -30,7 +31,7 @@ public class ChannelObject : IDisposable private bool _disposed = false; private static readonly ConcurrentDictionary _dataMap = new ConcurrentDictionary(); private static readonly object _dataLock = new object(); - private static int _dataId = 0; + private static int _dataId = 1; /// /// Constructor for creating a new channel object with specified ID and data. @@ -109,8 +110,19 @@ public object Data set { int id; + Interop.LibTizenCore.TizenCoreChannel.ObjectGetData(_handle, out IntPtr handle); + if (handle != IntPtr.Zero) + { + id = (int)handle; + _dataMap.TryRemove(id, out var _); + } + lock (_dataLock) { + if (_dataId + 1 < 0) + { + _dataId = 1; + } id = _dataId++; } _dataMap[id] = value;