From: dongsug.song Date: Fri, 26 Jan 2018 06:32:51 +0000 (+0900) Subject: [NUI] fix memory leak problem X-Git-Tag: accepted/tizen/4.0/unified/20180131.050210~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F80%2F168380%2F3;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [NUI] fix memory leak problem Conflicts: src/Tizen.NUI/src/public/BaseComponents/View.cs Change-Id: Ifbc9703e19bab871dc62bb9ac71159c5450d8bfd Signed-off-by: dongsug.song --- diff --git a/src/Tizen.NUI/src/internal/FrameBuffer.cs b/src/Tizen.NUI/src/internal/FrameBuffer.cs index 4b5abc1..085bdb1 100755 --- a/src/Tizen.NUI/src/internal/FrameBuffer.cs +++ b/src/Tizen.NUI/src/internal/FrameBuffer.cs @@ -15,6 +15,8 @@ * */ +using System.Runtime.InteropServices; + namespace Tizen.NUI { @@ -97,8 +99,12 @@ namespace Tizen.NUI public Texture GetColorTexture() { + //to fix memory leak issue, match the handle count with native side. global::System.IntPtr cPtr = NDalicPINVOKE.FrameBuffer_GetColorTexture(swigCPtr); - Texture ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Texture; + HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); + Texture ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as Texture; + NDalicPINVOKE.delete_BaseHandle(CPtr); + CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; diff --git a/src/Tizen.NUI/src/internal/ViewWrapperImpl.cs b/src/Tizen.NUI/src/internal/ViewWrapperImpl.cs index c1cb572..3c009a6 100755 --- a/src/Tizen.NUI/src/internal/ViewWrapperImpl.cs +++ b/src/Tizen.NUI/src/internal/ViewWrapperImpl.cs @@ -14,6 +14,7 @@ * limitations under the License. * */ +using System.Runtime.InteropServices; using Tizen.NUI.BaseComponents; namespace Tizen.NUI { @@ -251,8 +252,12 @@ namespace Tizen.NUI public VisualBase GetVisual(int index) { + //to fix memory leak issue, match the handle count with native side. System.IntPtr cPtr = NDalicManualPINVOKE.ViewWrapperImpl_GetVisual(swigCPtr, index); - VisualBase ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as VisualBase; + HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); + VisualBase ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as VisualBase; + NDalicPINVOKE.delete_BaseHandle(CPtr); + CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; diff --git a/src/Tizen.NUI/src/public/BaseComponents/TableView.cs b/src/Tizen.NUI/src/public/BaseComponents/TableView.cs index f4801fa..be2115c 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TableView.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TableView.cs @@ -17,6 +17,7 @@ using System; using System.ComponentModel; +using System.Runtime.InteropServices; namespace Tizen.NUI.BaseComponents { @@ -49,12 +50,12 @@ namespace Tizen.NUI.BaseComponents /// 3 protected override void Dispose(DisposeTypes type) { - if(disposed) + if (disposed) { return; } - if(type == DisposeTypes.Explicit) + if (type == DisposeTypes.Explicit) { //Called by User //Release your own managed resources here. @@ -135,7 +136,7 @@ namespace Tizen.NUI.BaseComponents /// 3 ~CellPosition() { - if(!isDisposeQueued) + if (!isDisposeQueued) { isDisposeQueued = true; DisposeQueue.Instance.Add(this); @@ -177,7 +178,7 @@ namespace Tizen.NUI.BaseComponents return; } - if(type == DisposeTypes.Explicit) + if (type == DisposeTypes.Explicit) { //Called by User //Release your own managed resources here. @@ -378,8 +379,12 @@ namespace Tizen.NUI.BaseComponents /// 3 public View GetChildAt(TableView.CellPosition position) { + //to fix memory leak issue, match the handle count with native side. IntPtr cPtr = NDalicPINVOKE.TableView_GetChildAt(swigCPtr, TableView.CellPosition.getCPtr(position)); - View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View; + HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); + View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View; + NDalicPINVOKE.delete_BaseHandle(CPtr); + CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; @@ -393,8 +398,12 @@ namespace Tizen.NUI.BaseComponents /// 3 public View RemoveChildAt(TableView.CellPosition position) { + //to fix memory leak issue, match the handle count with native side. IntPtr cPtr = NDalicPINVOKE.TableView_RemoveChildAt(swigCPtr, TableView.CellPosition.getCPtr(position)); - View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View; + HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); + View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View; + NDalicPINVOKE.delete_BaseHandle(CPtr); + CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; diff --git a/src/Tizen.NUI/src/public/BaseComponents/View.cs b/src/Tizen.NUI/src/public/BaseComponents/View.cs index 762bc29..efe00e7 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/View.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/View.cs @@ -32,7 +32,10 @@ namespace Tizen.NUI.BaseComponents internal View(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.View_SWIGUpcast(cPtr), cMemoryOwn) { swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); - PositionUsesPivotPoint = false; + if (HasBody()) + { + PositionUsesPivotPoint = false; + } } internal static global::System.Runtime.InteropServices.HandleRef getCPtr(View obj) @@ -111,6 +114,7 @@ namespace Tizen.NUI.BaseComponents /// 4 public override Container GetParent() { + //to fix memory leak issue, match the handle count with native side. IntPtr cPtr = NDalicPINVOKE.Actor_GetParent(swigCPtr); HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); BaseHandle basehandle = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle); @@ -125,7 +129,7 @@ namespace Tizen.NUI.BaseComponents internal bool IsTopLevelView() { - if(GetParent() is Layer) + if (GetParent() is Layer) { return true; } @@ -139,12 +143,12 @@ namespace Tizen.NUI.BaseComponents /// 3 protected override void Dispose(DisposeTypes type) { - if(disposed) + if (disposed) { return; } - if(type == DisposeTypes.Explicit) + if (type == DisposeTypes.Explicit) { //Called by User //Release your own managed resources here. @@ -429,9 +433,9 @@ namespace Tizen.NUI.BaseComponents Delegate[] delegateList = _keyEventHandler.GetInvocationList(); // Oring the result of each callback. - foreach ( EventHandlerWithReturnType del in delegateList ) + foreach (EventHandlerWithReturnType del in delegateList) { - result |= del( this, e ); + result |= del(this, e); } } @@ -1393,7 +1397,7 @@ namespace Tizen.NUI.BaseComponents /// background visual, creates one with transparent black as it's mixColor. /// /// 3 - public Animation AnimateBackgroundColor( object destinationValue, + public Animation AnimateBackgroundColor(object destinationValue, int startTime, int endTime, AlphaFunction.BuiltinFunctions? alphaFunction = null, @@ -1401,51 +1405,51 @@ namespace Tizen.NUI.BaseComponents { Tizen.NUI.PropertyMap background = Background; - if( background.Empty() ) + if (background.Empty()) { // If there is no background yet, ensure there is a transparent // color visual BackgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.0f); background = Background; } - return AnimateColor( "background", destinationValue, startTime, endTime, alphaFunction, initialValue ); + return AnimateColor("background", destinationValue, startTime, endTime, alphaFunction, initialValue); } /// /// Creates an animation to animate the mixColor of the named visual. /// /// 3 - public Animation AnimateColor( string targetVisual, object destinationColor, int startTime, int endTime, AlphaFunction.BuiltinFunctions? alphaFunction = null, object initialColor = null ) + public Animation AnimateColor(string targetVisual, object destinationColor, int startTime, int endTime, AlphaFunction.BuiltinFunctions? alphaFunction = null, object initialColor = null) { Animation animation = null; { PropertyMap _animator = new PropertyMap(); - if( alphaFunction != null ) + if (alphaFunction != null) { - _animator.Add("alphaFunction", new PropertyValue( AlphaFunction.BuiltinToPropertyKey(alphaFunction) ) ); + _animator.Add("alphaFunction", new PropertyValue(AlphaFunction.BuiltinToPropertyKey(alphaFunction))); } PropertyMap _timePeriod = new PropertyMap(); - _timePeriod.Add( "duration", new PropertyValue((endTime-startTime)/1000.0f) ); - _timePeriod.Add( "delay", new PropertyValue( startTime/1000.0f ) ); - _animator.Add( "timePeriod", new PropertyValue( _timePeriod ) ); + _timePeriod.Add("duration", new PropertyValue((endTime - startTime) / 1000.0f)); + _timePeriod.Add("delay", new PropertyValue(startTime / 1000.0f)); + _animator.Add("timePeriod", new PropertyValue(_timePeriod)); PropertyMap _transition = new PropertyMap(); - _transition.Add( "animator", new PropertyValue( _animator ) ); - _transition.Add( "target", new PropertyValue( targetVisual ) ); - _transition.Add( "property", new PropertyValue( "mixColor" ) ); + _transition.Add("animator", new PropertyValue(_animator)); + _transition.Add("target", new PropertyValue(targetVisual)); + _transition.Add("property", new PropertyValue("mixColor")); - if( initialColor != null ) + if (initialColor != null) { - PropertyValue initValue = PropertyValue.CreateFromObject( initialColor ); - _transition.Add( "initialValue", initValue ); + PropertyValue initValue = PropertyValue.CreateFromObject(initialColor); + _transition.Add("initialValue", initValue); } - PropertyValue destValue = PropertyValue.CreateFromObject( destinationColor ); - _transition.Add( "targetValue", destValue ); - TransitionData _transitionData = new TransitionData( _transition ); + PropertyValue destValue = PropertyValue.CreateFromObject(destinationColor); + _transition.Add("targetValue", destValue); + TransitionData _transitionData = new TransitionData(_transition); - animation = new Animation( NDalicManualPINVOKE.View_CreateTransition(swigCPtr, TransitionData.getCPtr(_transitionData)), true ); + animation = new Animation(NDalicManualPINVOKE.View_CreateTransition(swigCPtr, TransitionData.getCPtr(_transitionData)), true); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } @@ -1487,7 +1491,7 @@ namespace Tizen.NUI.BaseComponents get { Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap(); - GetProperty( View.Property.BACKGROUND ).Get(temp); + GetProperty(View.Property.BACKGROUND).Get(temp); return temp; } set @@ -1513,21 +1517,21 @@ namespace Tizen.NUI.BaseComponents switch (temp) { case 0: - { - return States.Normal; - } + { + return States.Normal; + } case 1: - { - return States.Focused; - } + { + return States.Focused; + } case 2: - { - return States.Disabled; - } + { + return States.Disabled; + } default: - { - return States.Normal; - } + { + return States.Normal; + } } } set @@ -1567,25 +1571,25 @@ namespace Tizen.NUI.BaseComponents switch (value) { case States.Normal: - { - valueToString = "NORMAL"; - break; - } + { + valueToString = "NORMAL"; + break; + } case States.Focused: - { - valueToString = "FOCUSED"; - break; - } + { + valueToString = "FOCUSED"; + break; + } case States.Disabled: - { - valueToString = "DISABLED"; - break; - } + { + valueToString = "DISABLED"; + break; + } default: - { - valueToString = "NORMAL"; - break; - } + { + valueToString = "NORMAL"; + break; + } } SetProperty(View.Property.SUB_STATE, new Tizen.NUI.PropertyValue(valueToString)); } @@ -1821,25 +1825,25 @@ namespace Tizen.NUI.BaseComponents switch (value) { case Tizen.NUI.HorizontalAlignmentType.Left: - { - valueToString = "left"; - break; - } + { + valueToString = "left"; + break; + } case Tizen.NUI.HorizontalAlignmentType.Center: - { - valueToString = "center"; - break; - } + { + valueToString = "center"; + break; + } case Tizen.NUI.HorizontalAlignmentType.Right: - { - valueToString = "right"; - break; - } + { + valueToString = "right"; + break; + } default: - { - valueToString = "left"; - break; - } + { + valueToString = "left"; + break; + } } SetProperty(TableView.ChildProperty.CELL_HORIZONTAL_ALIGNMENT, new Tizen.NUI.PropertyValue(valueToString)); } @@ -1877,25 +1881,25 @@ namespace Tizen.NUI.BaseComponents switch (value) { case Tizen.NUI.VerticalAlignmentType.Top: - { - valueToString = "top"; - break; - } + { + valueToString = "top"; + break; + } case Tizen.NUI.VerticalAlignmentType.Center: - { - valueToString = "center"; - break; - } + { + valueToString = "center"; + break; + } case Tizen.NUI.VerticalAlignmentType.Bottom: - { - valueToString = "bottom"; - break; - } + { + valueToString = "bottom"; + break; + } default: - { - valueToString = "top"; - break; - } + { + valueToString = "top"; + break; + } } SetProperty(TableView.ChildProperty.CELL_VERTICAL_ALIGNMENT, new Tizen.NUI.PropertyValue(valueToString)); } @@ -1920,7 +1924,7 @@ namespace Tizen.NUI.BaseComponents } set { - if(value) + if (value) { LeftFocusableViewId = (int)value.GetId(); } @@ -1950,7 +1954,7 @@ namespace Tizen.NUI.BaseComponents } set { - if(value) + if (value) { RightFocusableViewId = (int)value.GetId(); } @@ -1980,7 +1984,7 @@ namespace Tizen.NUI.BaseComponents } set { - if(value) + if (value) { UpFocusableViewId = (int)value.GetId(); } @@ -2010,7 +2014,7 @@ namespace Tizen.NUI.BaseComponents } set { - if(value) + if (value) { DownFocusableViewId = (int)value.GetId(); } @@ -2609,8 +2613,12 @@ namespace Tizen.NUI.BaseComponents [EditorBrowsable(EditorBrowsableState.Never)] public Layer GetLayer() { + //to fix memory leak issue, match the handle count with native side. IntPtr cPtr = NDalicPINVOKE.Actor_GetLayer(swigCPtr); - Layer ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Layer; + HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); + Layer ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as Layer; + NDalicPINVOKE.delete_BaseHandle(CPtr); + CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); @@ -2637,6 +2645,7 @@ namespace Tizen.NUI.BaseComponents /// 3 public View FindChildByName(string viewName) { + //to fix memory leak issue, match the handle count with native side. IntPtr cPtr = NDalicPINVOKE.Actor_FindChildByName(swigCPtr, viewName); HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View; @@ -2650,6 +2659,7 @@ namespace Tizen.NUI.BaseComponents internal View FindChildById(uint id) { + //to fix memory leak issue, match the handle count with native side. IntPtr cPtr = NDalicPINVOKE.Actor_FindChildById(swigCPtr, id); HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View; @@ -3248,8 +3258,12 @@ namespace Tizen.NUI.BaseComponents /// 3 public Renderer GetRendererAt(uint index) { + //to fix memory leak issue, match the handle count with native side. IntPtr cPtr = NDalicPINVOKE.Actor_GetRendererAt(swigCPtr, index); - Renderer ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Renderer; + HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); + Renderer ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as Renderer; + NDalicPINVOKE.delete_BaseHandle(CPtr); + CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); @@ -3924,13 +3938,13 @@ namespace Tizen.NUI.BaseComponents switch (temp) { case "NORMAL": - return DrawModeType.Normal; + return DrawModeType.Normal; case "OVERLAY_2D": - return DrawModeType.Overlay2D; + return DrawModeType.Overlay2D; case "STENCIL": - return DrawModeType.Stencil; + return DrawModeType.Stencil; default: - return DrawModeType.Normal; + return DrawModeType.Normal; } } set @@ -4223,13 +4237,13 @@ namespace Tizen.NUI.BaseComponents switch (temp) { case "DISABLED": - return ClippingModeType.Disabled; + return ClippingModeType.Disabled; case "CLIP_CHILDREN": - return ClippingModeType.ClipChildren; + return ClippingModeType.ClipChildren; case "CLIP_TO_BOUNDING_BOX": - return ClippingModeType.ClipToBoundingBox; + return ClippingModeType.ClipToBoundingBox; default: - return ClippingModeType.Disabled; + return ClippingModeType.Disabled; } } set diff --git a/src/Tizen.NUI/src/public/FocusManager.cs b/src/Tizen.NUI/src/public/FocusManager.cs index 2794627..f8fd384 100755 --- a/src/Tizen.NUI/src/public/FocusManager.cs +++ b/src/Tizen.NUI/src/public/FocusManager.cs @@ -449,9 +449,13 @@ namespace Tizen.NUI /// 3 public View GetCurrentFocusView() { + //to fix memory leak issue, match the handle count with native side. IntPtr cPtr = NDalicManualPINVOKE.FocusManager_GetCurrentFocusActor(swigCPtr); + HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); + View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View; + NDalicPINVOKE.delete_BaseHandle(CPtr); + CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); - View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View; return ret; } @@ -553,17 +557,12 @@ namespace Tizen.NUI /// 3 public View GetFocusGroup(View view) { + //to fix memory leak issue, match the handle count with native side. IntPtr cPtr = NDalicManualPINVOKE.FocusManager_GetFocusGroup(swigCPtr, View.getCPtr(view)); - - View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View; - - - /*View ret = new View(NDalicManualPINVOKE.FocusManager_GetFocusGroup(swigCPtr, View.getCPtr(view)), true); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - if (ret.HasBody() == false) - { - return null; - }*/ + HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); + View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View; + NDalicPINVOKE.delete_BaseHandle(CPtr); + CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); return ret; } @@ -593,9 +592,12 @@ namespace Tizen.NUI internal View GetFocusIndicatorView() { + //to fix memory leak issue, match the handle count with native side. IntPtr cPtr = NDalicManualPINVOKE.FocusManager_GetFocusIndicatorActor(swigCPtr); - - View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View; + HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); + View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View; + NDalicPINVOKE.delete_BaseHandle(CPtr); + CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); return ret; } diff --git a/src/Tizen.NUI/src/public/Layer.cs b/src/Tizen.NUI/src/public/Layer.cs index 37efd13..11f6f49 100755 --- a/src/Tizen.NUI/src/public/Layer.cs +++ b/src/Tizen.NUI/src/public/Layer.cs @@ -212,6 +212,7 @@ namespace Tizen.NUI /// 3 public View FindChildById(uint id) { + //to fix memory leak issue, match the handle count with native side. IntPtr cPtr = NDalicPINVOKE.Actor_FindChildById(swigCPtr, id); HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View; diff --git a/src/Tizen.NUI/src/public/Renderer.cs b/src/Tizen.NUI/src/public/Renderer.cs index 2556d75..e345ddd 100755 --- a/src/Tizen.NUI/src/public/Renderer.cs +++ b/src/Tizen.NUI/src/public/Renderer.cs @@ -15,6 +15,8 @@ * */ +using System.Runtime.InteropServices; + namespace Tizen.NUI { /// @@ -229,8 +231,12 @@ namespace Tizen.NUI /// 3 public Geometry GetGeometry() { + //to fix memory leak issue, match the handle count with native side. System.IntPtr cPtr = NDalicPINVOKE.Renderer_GetGeometry(swigCPtr); - Geometry ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Geometry; + HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); + Geometry ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as Geometry; + NDalicPINVOKE.delete_BaseHandle(CPtr); + CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; @@ -266,8 +272,12 @@ namespace Tizen.NUI /// 3 public TextureSet GetTextures() { + //to fix memory leak issue, match the handle count with native side. System.IntPtr cPtr = NDalicPINVOKE.Renderer_GetTextures(swigCPtr); - TextureSet ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as TextureSet; + HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); + TextureSet ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as TextureSet; + NDalicPINVOKE.delete_BaseHandle(CPtr); + CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; @@ -291,8 +301,12 @@ namespace Tizen.NUI /// 3 public Shader GetShader() { + //to fix memory leak issue, match the handle count with native side. System.IntPtr cPtr = NDalicPINVOKE.Renderer_GetShader(swigCPtr); - Shader ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Shader; + HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); + Shader ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as Shader; + NDalicPINVOKE.delete_BaseHandle(CPtr); + CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; diff --git a/src/Tizen.NUI/src/public/TextureSet.cs b/src/Tizen.NUI/src/public/TextureSet.cs index 6951097..949dece 100755 --- a/src/Tizen.NUI/src/public/TextureSet.cs +++ b/src/Tizen.NUI/src/public/TextureSet.cs @@ -15,6 +15,8 @@ * */ +using System.Runtime.InteropServices; + namespace Tizen.NUI { /// @@ -102,8 +104,12 @@ namespace Tizen.NUI /// 3 public Texture GetTexture(uint index) { + //to fix memory leak issue, match the handle count with native side. System.IntPtr cPtr = NDalicPINVOKE.TextureSet_GetTexture(swigCPtr, index); - Texture ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Texture; + HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); + Texture ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as Texture; + NDalicPINVOKE.delete_BaseHandle(CPtr); + CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; @@ -129,8 +135,12 @@ namespace Tizen.NUI /// 3 public Sampler GetSampler(uint index) { + //to fix memory leak issue, match the handle count with native side. System.IntPtr cPtr = NDalicPINVOKE.TextureSet_GetSampler(swigCPtr, index); - Sampler ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Sampler; + HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); + Sampler ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as Sampler; + NDalicPINVOKE.delete_BaseHandle(CPtr); + CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; diff --git a/src/Tizen.NUI/src/public/Touch.cs b/src/Tizen.NUI/src/public/Touch.cs index 2fe9de8..635c679 100755 --- a/src/Tizen.NUI/src/public/Touch.cs +++ b/src/Tizen.NUI/src/public/Touch.cs @@ -17,6 +17,7 @@ namespace Tizen.NUI { + using System.Runtime.InteropServices; using Tizen.NUI.BaseComponents; /// /// Touch events are a collection of points at a specific moment in time.
@@ -164,8 +165,12 @@ namespace Tizen.NUI /// 3 public View GetHitView(uint point) { + //to fix memory leak issue, match the handle count with native side. global::System.IntPtr cPtr = NDalicPINVOKE.Touch_GetHitActor(swigCPtr, point); - View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View; + HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); + View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View; + NDalicPINVOKE.delete_BaseHandle(CPtr); + CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; diff --git a/src/Tizen.NUI/src/public/UIComponents/Popup.cs b/src/Tizen.NUI/src/public/UIComponents/Popup.cs index 0b81c5a..1a557ee 100755 --- a/src/Tizen.NUI/src/public/UIComponents/Popup.cs +++ b/src/Tizen.NUI/src/public/UIComponents/Popup.cs @@ -405,8 +405,12 @@ namespace Tizen.NUI.UIComponents internal View GetTitle() { + //to fix memory leak issue, match the handle count with native side. IntPtr cPtr = NDalicPINVOKE.Popup_GetTitle(swigCPtr); - View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View; + HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); + View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View; + NDalicPINVOKE.delete_BaseHandle(CPtr); + CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; @@ -425,8 +429,12 @@ namespace Tizen.NUI.UIComponents internal View GetContent() { + //to fix memory leak issue, match the handle count with native side. IntPtr cPtr = NDalicPINVOKE.Popup_GetContent(swigCPtr); - View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View; + HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); + View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View; + NDalicPINVOKE.delete_BaseHandle(CPtr); + CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; @@ -445,8 +453,12 @@ namespace Tizen.NUI.UIComponents internal View GetFooter() { + //to fix memory leak issue, match the handle count with native side. IntPtr cPtr = NDalicPINVOKE.Popup_GetFooter(swigCPtr); - View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View; + HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); + View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View; + NDalicPINVOKE.delete_BaseHandle(CPtr); + CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret;