Add ptr pool
authorXiaohui Fang <xiaohui.fang@samsung.com>
Tue, 11 Mar 2025 01:07:59 +0000 (09:07 +0800)
committerWonsik Jung <sidein@samsung.com>
Wed, 12 Mar 2025 04:26:52 +0000 (13:26 +0900)
src/Tizen.NUI/src/internal/Common/IntPtrPool.cs [new file with mode: 0755]
src/Tizen.NUI/src/public/Common/Position.cs
src/Tizen.NUI/src/public/Common/Position2D.cs
src/Tizen.NUI/src/public/Common/Vector2.cs
src/Tizen.NUI/src/public/Common/Vector3.cs
src/Tizen.NUI/src/public/Common/Vector4.cs

diff --git a/src/Tizen.NUI/src/internal/Common/IntPtrPool.cs b/src/Tizen.NUI/src/internal/Common/IntPtrPool.cs
new file mode 100755 (executable)
index 0000000..150d0d8
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright(c) 2025 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tizen.NUI
+{
+    internal class IntPtrPool
+    {
+        private System.Collections.Generic.Stack<IntPtr> pool = new System.Collections.Generic.Stack<IntPtr>();
+        private CreatePtrCallback createPtrCb;
+
+        public delegate IntPtr CreatePtrCallback();
+
+        public IntPtrPool(CreatePtrCallback createPtrCb)
+        {
+            this.createPtrCb = createPtrCb;
+        }
+
+        public IntPtr GetPtr()
+        {
+            IntPtr ret = IntPtr.Zero;
+
+            if (0 == pool.Count)
+            {
+                if (null == createPtrCb)
+                {
+                    throw new Exception("createPtrCb can't be null");
+                }
+
+                ret = createPtrCb();
+            }
+            else
+            {
+                ret = pool.Pop();
+            }
+
+            return ret;
+        }
+
+        public void PutPtr(IntPtr ptr)
+        {
+            pool.Push(ptr);
+        }
+    }
+}
index 774abc0f6aab573e20659afb13851ce5ae644f73..bee4051589e4b9644b243412d434cf00f063cc84 100755 (executable)
@@ -32,6 +32,26 @@ namespace Tizen.NUI
         private static readonly Position one = new Position(1.0f, 1.0f, 1.0f);
         private static readonly Position zero = new Position(0.0f, 0.0f, 0.0f);
 
+        private static IntPtrPool ptrPool;
+
+        private static IntPtrPool PtrPool
+        {
+            get
+            {
+                if (null == ptrPool)
+                {
+                    ptrPool = new IntPtrPool(CreateEmptryPtr);
+                }
+
+                return ptrPool;
+            }
+        }
+
+        private static IntPtr CreateEmptryPtr()
+        {
+            return Interop.Vector3.NewVector3();
+        }
+
         internal static new void Preload()
         {
             // Do nothing. Just call for load static values.
@@ -47,7 +67,7 @@ namespace Tizen.NUI
         /// view.Position = new Position2D(10, 10); // be aware that here the z value is 0.0f by default. <br />
         /// </remarks>
         /// <since_tizen> 3 </since_tizen>
-        public Position() : this(Interop.Vector3.NewVector3(), true)
+        public Position() : this(PtrPool.GetPtr(), true)
         {
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
@@ -65,8 +85,12 @@ namespace Tizen.NUI
         /// view.Position = new Position2D(10, 10); // be aware that here the z value is 0.0f by default. <br />
         /// </remarks>
         /// <since_tizen> 3 </since_tizen>
-        public Position(float x, float y, float z = 0.0f) : this(Interop.Vector3.NewVector3(x, y, z), true)
+        public Position(float x, float y, float z = 0.0f) : this(PtrPool.GetPtr(), true)
         {
+            Interop.Vector3.XSet(SwigCPtr, x);
+            Interop.Vector3.YSet(SwigCPtr, y);
+            Interop.Vector3.ZSet(SwigCPtr, z);
+
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
@@ -75,8 +99,16 @@ namespace Tizen.NUI
         /// </summary>
         /// <param name="position2d">Position2D to create this vector from.</param>
         /// <since_tizen> 3 </since_tizen>
-        public Position(Position2D position2d) : this(Interop.Vector3.NewVector3WithVector2(Position2D.getCPtr(position2d)), true)
+        public Position(Position2D position2d) : this(PtrPool.GetPtr(), true)
         {
+            if (null == position2d)
+            {
+                throw new ArgumentNullException(nameof(position2d));
+            }
+
+            Interop.Vector3.XSet(SwigCPtr, position2d.X);
+            Interop.Vector3.YSet(SwigCPtr, position2d.Y);
+
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
@@ -578,6 +610,30 @@ namespace Tizen.NUI
             return ret;
         }
 
+        /// This will not be public opened.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public new void Dispose()
+        {
+            if (!disposed)
+            {
+                disposed = true;
+                PtrPool.PutPtr(SwigCPtr.Handle);
+                SwigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+            }
+        }
+
+        /// This will not be public opened.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected override void Dispose(bool disposing)
+        {
+            if (!disposed)
+            {
+                disposed = true;
+                PtrPool.PutPtr(SwigCPtr.Handle);
+                SwigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+            }
+        }
+
         /// This will not be public opened.
         [EditorBrowsable(EditorBrowsableState.Never)]
         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
@@ -644,9 +700,14 @@ namespace Tizen.NUI
 
         internal delegate void PositionChangedCallback(float x, float y, float z);
 
-        internal Position(PositionChangedCallback cb, float x, float y, float z) : this(Interop.Vector3.NewVector3(x, y, z), true)
+        internal Position(PositionChangedCallback cb, float x, float y, float z) : this(PtrPool.GetPtr(), true)
         {
             callback = cb;
+
+            Interop.Vector3.XSet(SwigCPtr, x);
+            Interop.Vector3.YSet(SwigCPtr, y);
+            Interop.Vector3.ZSet(SwigCPtr, z);
+
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
index 90c6067283d661b94e231710507e22f6da420d9a..c3ed0039a00e52f70cbc2dc57b2ed1c379e6d310 100755 (executable)
@@ -29,6 +29,26 @@ namespace Tizen.NUI
     {
         private Position2DChangedCallback callback = null;
 
+        private static IntPtrPool ptrPool;
+
+        private static IntPtrPool PtrPool
+        {
+            get
+            {
+                if (null == ptrPool)
+                {
+                    ptrPool = new IntPtrPool(CreateEmptryPtr);
+                }
+
+                return ptrPool;
+            }
+        }
+
+        private static IntPtr CreateEmptryPtr()
+        {
+            return Interop.Vector2.NewVector2();
+        }
+
         /// <summary>
         /// The constructor.
         /// </summary>
@@ -39,7 +59,7 @@ namespace Tizen.NUI
         /// view.Position = new Position2D(10, 10); // be aware that here the z value is 0.0f by default. <br />
         /// </remarks>
         /// <since_tizen> 3 </since_tizen>
-        public Position2D() : this(Interop.Vector2.NewVector2(), true)
+        public Position2D() : this(PtrPool.GetPtr(), true)
         {
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
@@ -49,8 +69,16 @@ namespace Tizen.NUI
         /// </summary>
         /// <param name="position">Position to create this vector from</param>
         /// <since_tizen> 3 </since_tizen>
-        public Position2D(Position position) : this(Interop.Vector2.NewVector2WithVector3(Position.getCPtr(position)), true)
+        public Position2D(Position position) : this(PtrPool.GetPtr(), true)
         {
+            if (null == position)
+            {
+                throw new ArgumentNullException(nameof(position));
+            }
+
+            Interop.Vector2.XSet(SwigCPtr, position.X);
+            Interop.Vector2.YSet(SwigCPtr, position.Y);
+
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
@@ -66,8 +94,11 @@ namespace Tizen.NUI
         /// view.Position = new Position2D(10, 10); // be aware that here the z value is 0.0f by default. <br />
         /// </remarks>
         /// <since_tizen> 3 </since_tizen>
-        public Position2D(int x, int y) : this(Interop.Vector2.NewVector2((float)x, (float)y), true)
+        public Position2D(int x, int y) : this(PtrPool.GetPtr(), true)
         {
+            Interop.Vector2.XSet(SwigCPtr, x);
+            Interop.Vector2.YSet(SwigCPtr, y);
+
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
@@ -75,8 +106,11 @@ namespace Tizen.NUI
         {
         }
 
-        internal Position2D(Position2DChangedCallback cb, int x, int y) : this(Interop.Vector2.NewVector2((float)x, (float)y), true)
+        internal Position2D(Position2DChangedCallback cb, int x, int y) : this(PtrPool.GetPtr(), true)
         {
+            Interop.Vector2.XSet(SwigCPtr, x);
+            Interop.Vector2.YSet(SwigCPtr, y);
+
             callback = cb;
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
@@ -384,6 +418,30 @@ namespace Tizen.NUI
             return ret;
         }
 
+        /// This will not be public opened.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public new void Dispose()
+        {
+            if (!disposed)
+            {
+                disposed = true;
+                PtrPool.PutPtr(SwigCPtr.Handle);
+                SwigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+            }
+        }
+
+        /// This will not be public opened.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected override void Dispose(bool disposing)
+        {
+            if (!disposed)
+            {
+                disposed = true;
+                PtrPool.PutPtr(SwigCPtr.Handle);
+                SwigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+            }
+        }
+
         /// This will not be public opened.
         [EditorBrowsable(EditorBrowsableState.Never)]
         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
index 2d3067a2ce3d873fe3ac9d98f8e8ab034c808886..38531832580efbdc4d2d1b40172b1f4467c55212 100755 (executable)
@@ -20,7 +20,6 @@ using Tizen.NUI.Binding;
 
 namespace Tizen.NUI
 {
-
     /// <summary>
     /// A two-dimensional vector.
     /// </summary>
@@ -35,6 +34,26 @@ namespace Tizen.NUI
         private static readonly Vector2 negativeXaxis = new Vector2(-1.0f, 0.0f);
         private static readonly Vector2 negativeYaxis = new Vector2(0.0f, -1.0f);
 
+        private static IntPtrPool ptrPool;
+
+        private static IntPtrPool PtrPool
+        {
+            get
+            {
+                if (null == ptrPool)
+                {
+                    ptrPool = new IntPtrPool(CreateEmptryPtr);
+                }
+
+                return ptrPool;
+            }
+        }
+
+        private static IntPtr CreateEmptryPtr()
+        {
+            return Interop.Vector2.NewVector2();
+        }
+
         internal static new void Preload()
         {
             // Do nothing. Just call for load static values.
@@ -44,7 +63,7 @@ namespace Tizen.NUI
         /// The default constructor initializes the vector to 0.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
-        public Vector2() : this(Interop.Vector2.NewVector2(), true)
+        public Vector2() : this(PtrPool.GetPtr(), true)
         {
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
@@ -55,8 +74,11 @@ namespace Tizen.NUI
         /// <param name="x">The x or width component.</param>
         /// <param name="y">The y or height component.</param>
         /// <since_tizen> 3 </since_tizen>
-        public Vector2(float x, float y) : this(Interop.Vector2.NewVector2(x, y), true)
+        public Vector2(float x, float y) : this(PtrPool.GetPtr(), true)
         {
+            Interop.Vector2.XSet(SwigCPtr, x);
+            Interop.Vector2.YSet(SwigCPtr, y);
+
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
@@ -65,8 +87,15 @@ namespace Tizen.NUI
         /// </summary>
         /// <param name="array">The array of xy.</param>
         /// <since_tizen> 3 </since_tizen>
-        public Vector2(float[] array) : this(Interop.Vector2.NewVector2(array), true)
+        public Vector2(float[] array) : this(PtrPool.GetPtr(), true)
         {
+            if (null == array)
+            {
+                throw new ArgumentNullException(nameof(array));
+            }
+
+            Interop.Vector2.XSet(SwigCPtr, array[0]);
+            Interop.Vector2.YSet(SwigCPtr, array[1]);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
@@ -85,8 +114,15 @@ namespace Tizen.NUI
         /// </summary>
         /// <param name="vec3">Vector3 to create this vector from.</param>
         /// <since_tizen> 3 </since_tizen>
-        public Vector2(Vector3 vec3) : this(Interop.Vector2.NewVector2WithVector3(Vector3.getCPtr(vec3)), true)
+        public Vector2(Vector3 vec3) : this(PtrPool.GetPtr(), true)
         {
+            if (null == vec3)
+            {
+                throw new ArgumentNullException(nameof(vec3));
+            }
+
+            Interop.Vector2.XSet(SwigCPtr, vec3.X);
+            Interop.Vector2.YSet(SwigCPtr, vec3.Y);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
@@ -95,8 +131,16 @@ namespace Tizen.NUI
         /// </summary>
         /// <param name="vec4">Vector4 to create this vector from.</param>
         /// <since_tizen> 3 </since_tizen>
-        public Vector2(Vector4 vec4) : this(Interop.Vector2.NewVector2WithVector4(Vector4.getCPtr(vec4)), true)
+        public Vector2(Vector4 vec4) : this(PtrPool.GetPtr(), true)
         {
+            if (null == vec4)
+            {
+                throw new ArgumentNullException(nameof(vec4));
+            }
+
+            Interop.Vector2.XSet(SwigCPtr, vec4.X);
+            Interop.Vector2.YSet(SwigCPtr, vec4.Y);
+
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
@@ -104,9 +148,12 @@ namespace Tizen.NUI
         {
         }
 
-        internal Vector2(Vector2ChangedCallback cb, float x, float y) : this(Interop.Vector2.NewVector2(x, y), true)
+        internal Vector2(Vector2ChangedCallback cb, float x, float y) : this(PtrPool.GetPtr(), true)
         {
+            Interop.Vector2.XSet(SwigCPtr, x);
+            Interop.Vector2.YSet(SwigCPtr, y);
             callback = cb;
+
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
@@ -469,6 +516,30 @@ namespace Tizen.NUI
             return ret;
         }
 
+        /// This will not be public opened.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public new void Dispose()
+        {
+            if (!disposed)
+            {
+                disposed = true;
+                PtrPool.PutPtr(SwigCPtr.Handle);
+                SwigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+            }
+        }
+
+        /// This will not be public opened.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected override void Dispose(bool disposing)
+        {
+            if (!disposed)
+            {
+                disposed = true;
+                PtrPool.PutPtr(SwigCPtr.Handle);
+                SwigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+            }
+        }
+
         /// This will not be public opened.
         [EditorBrowsable(EditorBrowsableState.Never)]
         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
index 3fae030487e0f551782aa8a76fcb279bb2fbf345..d4382d1f39c0a4b88f30277567b023ee038cfbc3 100755 (executable)
@@ -37,6 +37,26 @@ namespace Tizen.NUI
         private static readonly Vector3 negativeYaxis = new Vector3(0.0f, -1.0f, 0.0f);
         private static readonly Vector3 negativeZaxis = new Vector3(0.0f, 0.0f, -1.0f);
 
+        private static IntPtrPool ptrPool;
+
+        private static IntPtrPool PtrPool
+        {
+            get
+            {
+                if (null == ptrPool)
+                {
+                    ptrPool = new IntPtrPool(CreateEmptryPtr);
+                }
+
+                return ptrPool;
+            }
+        }
+
+        private static IntPtr CreateEmptryPtr()
+        {
+            return Interop.Vector3.NewVector3();
+        }
+
         internal static new void Preload()
         {
             // Do nothing. Just call for load static values.
@@ -46,7 +66,7 @@ namespace Tizen.NUI
         /// The default constructor of Vector3 class.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
-        public Vector3() : this(Interop.Vector3.NewVector3(), true)
+        public Vector3() : this(PtrPool.GetPtr(), true)
         {
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
@@ -58,8 +78,12 @@ namespace Tizen.NUI
         /// <param name="y">The y (or height) component.</param>
         /// <param name="z">The z (or depth) component.</param>
         /// <since_tizen> 3 </since_tizen>
-        public Vector3(float x, float y, float z) : this(Interop.Vector3.NewVector3(x, y, z), true)
+        public Vector3(float x, float y, float z) : this(PtrPool.GetPtr(), true)
         {
+            Interop.Vector3.XSet(SwigCPtr, x);
+            Interop.Vector3.YSet(SwigCPtr, y);
+            Interop.Vector3.ZSet(SwigCPtr, z);
+
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
@@ -68,8 +92,17 @@ namespace Tizen.NUI
         /// </summary>
         /// <param name="array">An array of xyz.</param>
         /// <since_tizen> 3 </since_tizen>
-        public Vector3(float[] array) : this(Interop.Vector3.NewVector3(array), true)
+        public Vector3(float[] array) : this(PtrPool.GetPtr(), true)
         {
+            if (null == array)
+            {
+                throw new ArgumentNullException(nameof(array));
+            }
+
+            Interop.Vector3.XSet(SwigCPtr, array[0]);
+            Interop.Vector3.YSet(SwigCPtr, array[1]);
+            Interop.Vector3.ZSet(SwigCPtr, array[2]);
+
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
@@ -78,8 +111,16 @@ namespace Tizen.NUI
         /// </summary>
         /// <param name="vec2">Vector2 to create this vector from.</param>
         /// <since_tizen> 3 </since_tizen>
-        public Vector3(Vector2 vec2) : this(Interop.Vector3.NewVector3WithVector2(Vector2.getCPtr(vec2)), true)
+        public Vector3(Vector2 vec2) : this(PtrPool.GetPtr(), true)
         {
+            if (null == vec2)
+            {
+                throw new ArgumentNullException(nameof(vec2));
+            }
+
+            Interop.Vector3.XSet(SwigCPtr, vec2.X);
+            Interop.Vector3.YSet(SwigCPtr, vec2.Y);
+
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
@@ -88,8 +129,17 @@ namespace Tizen.NUI
         /// </summary>
         /// <param name="vec4">Vector4 to create this vector from.</param>
         /// <since_tizen> 3 </since_tizen>
-        public Vector3(Vector4 vec4) : this(Interop.Vector3.NewVector3WithVector4(Vector4.getCPtr(vec4)), true)
+        public Vector3(Vector4 vec4) : this(PtrPool.GetPtr(), true)
         {
+            if (null == vec4)
+            {
+                throw new ArgumentNullException(nameof(vec4));
+            }
+
+            Interop.Vector3.XSet(SwigCPtr, vec4.X);
+            Interop.Vector3.YSet(SwigCPtr, vec4.Y);
+            Interop.Vector3.ZSet(SwigCPtr, vec4.Z);
+
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
@@ -97,8 +147,12 @@ namespace Tizen.NUI
         {
         }
 
-        internal Vector3(Vector3ChangedCallback cb, float x, float y, float z) : this(Interop.Vector3.NewVector3(x, y, z), true)
+        internal Vector3(Vector3ChangedCallback cb, float x, float y, float z) : this(PtrPool.GetPtr(), true)
         {
+            Interop.Vector3.XSet(SwigCPtr, x);
+            Interop.Vector3.YSet(SwigCPtr, y);
+            Interop.Vector3.ZSet(SwigCPtr, z);
+
             callback = cb;
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
@@ -658,6 +712,30 @@ namespace Tizen.NUI
             return ret;
         }
 
+        /// This will not be public opened.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public new void Dispose()
+        {
+            if (!disposed)
+            {
+                disposed = true;
+                PtrPool.PutPtr(SwigCPtr.Handle);
+                SwigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+            }
+        }
+
+        /// This will not be public opened.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected override void Dispose(bool disposing)
+        {
+            if (!disposed)
+            {
+                disposed = true;
+                PtrPool.PutPtr(SwigCPtr.Handle);
+                SwigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+            }
+        }
+
         /// This will not be public opened.
         [EditorBrowsable(EditorBrowsableState.Never)]
         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
index bbb7deb49953b8f1fdd2f64cbf0777fca819c166..2c77c04e789e3703ac5e1b93172d3c6b8a897dea 100755 (executable)
@@ -34,6 +34,26 @@ namespace Tizen.NUI
         private static readonly Vector4 yaxis = new Vector4(0.0f, 1.0f, 0.0f, 0.0f);
         private static readonly Vector4 zaxis = new Vector4(0.0f, 0.0f, 1.0f, 0.0f);
 
+        private static IntPtrPool ptrPool;
+
+        private static IntPtrPool PtrPool
+        {
+            get
+            {
+                if (null == ptrPool)
+                {
+                    ptrPool = new IntPtrPool(CreateEmptryPtr);
+                }
+
+                return ptrPool;
+            }
+        }
+
+        private static IntPtr CreateEmptryPtr()
+        {
+            return Interop.Vector4.NewVector4();
+        }
+
         internal static new void Preload()
         {
             // Do nothing. Just call for load static values.
@@ -43,7 +63,7 @@ namespace Tizen.NUI
         /// The default constructor initializes the vector to 0.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
-        public Vector4() : this(Interop.Vector4.NewVector4(), true)
+        public Vector4() : this(PtrPool.GetPtr(), true)
         {
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
@@ -56,8 +76,13 @@ namespace Tizen.NUI
         /// <param name="z">The z (or b/p) component.</param>
         /// <param name="w">The w (or a/q) component.</param>
         /// <since_tizen> 3 </since_tizen>
-        public Vector4(float x, float y, float z, float w) : this(Interop.Vector4.NewVector4(x, y, z, w), true)
+        public Vector4(float x, float y, float z, float w) : this(PtrPool.GetPtr(), true)
         {
+            Interop.Vector4.XSet(SwigCPtr, x);
+            Interop.Vector4.YSet(SwigCPtr, y);
+            Interop.Vector4.ZSet(SwigCPtr, z);
+            Interop.Vector4.WSet(SwigCPtr, w);
+
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
@@ -66,8 +91,18 @@ namespace Tizen.NUI
         /// </summary>
         /// <param name="array">The array of either xyzw/rgba/stpq.</param>
         /// <since_tizen> 3 </since_tizen>
-        public Vector4(float[] array) : this(Interop.Vector4.NewVector4(array), true)
+        public Vector4(float[] array) : this(PtrPool.GetPtr(), true)
         {
+            if (null == array)
+            {
+                throw new ArgumentNullException(nameof(array));
+            }
+
+            Interop.Vector4.XSet(SwigCPtr, array[0]);
+            Interop.Vector4.YSet(SwigCPtr, array[1]);
+            Interop.Vector4.ZSet(SwigCPtr, array[2]);
+            Interop.Vector4.WSet(SwigCPtr, array[3]);
+
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
@@ -76,8 +111,16 @@ namespace Tizen.NUI
         /// </summary>
         /// <param name="vec2">Vector2 to copy from, z and w are initialized to 0.</param>
         /// <since_tizen> 3 </since_tizen>
-        public Vector4(Vector2 vec2) : this(Interop.Vector4.NewVector4WithVector2(Vector2.getCPtr(vec2)), true)
+        public Vector4(Vector2 vec2) : this(PtrPool.GetPtr(), true)
         {
+            if (null == vec2)
+            {
+                throw new ArgumentNullException(nameof(vec2));
+            }
+
+            Interop.Vector4.XSet(SwigCPtr, vec2.X);
+            Interop.Vector4.YSet(SwigCPtr, vec2.Y);
+
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
@@ -86,8 +129,17 @@ namespace Tizen.NUI
         /// </summary>
         /// <param name="vec3">Vector3 to copy from, w is initialized to 0.</param>
         /// <since_tizen> 3 </since_tizen>
-        public Vector4(Vector3 vec3) : this(Interop.Vector4.NewVector4WithVector3(Vector3.getCPtr(vec3)), true)
+        public Vector4(Vector3 vec3) : this(PtrPool.GetPtr(), true)
         {
+            if (null == vec3)
+            {
+                throw new ArgumentNullException(nameof(vec3));
+            }
+
+            Interop.Vector4.XSet(SwigCPtr, vec3.X);
+            Interop.Vector4.YSet(SwigCPtr, vec3.Y);
+            Interop.Vector4.ZSet(SwigCPtr, vec3.Z);
+
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
@@ -95,8 +147,13 @@ namespace Tizen.NUI
         {
         }
 
-        internal Vector4(Vector4ChangedCallback cb, float x, float y, float z, float w) : this(Interop.Vector4.NewVector4(x, y, z, w), true)
+        internal Vector4(Vector4ChangedCallback cb, float x, float y, float z, float w) : this(PtrPool.GetPtr(), true)
         {
+            Interop.Vector4.XSet(SwigCPtr, x);
+            Interop.Vector4.YSet(SwigCPtr, y);
+            Interop.Vector4.ZSet(SwigCPtr, z);
+            Interop.Vector4.WSet(SwigCPtr, w);
+
             callback = cb;
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
@@ -760,6 +817,30 @@ namespace Tizen.NUI
             return ret;
         }
 
+        /// This will not be public opened.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public new void Dispose()
+        {
+            if (!disposed)
+            {
+                disposed = true;
+                PtrPool.PutPtr(SwigCPtr.Handle);
+                SwigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+            }
+        }
+
+        /// This will not be public opened.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected override void Dispose(bool disposing)
+        {
+            if (!disposed)
+            {
+                disposed = true;
+                PtrPool.PutPtr(SwigCPtr.Handle);
+                SwigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+            }
+        }
+
         /// This will not be public opened.
         [EditorBrowsable(EditorBrowsableState.Never)]
         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)