Browse Source
* Fix Metal renderer memory leakage on macOS * Remove no-op ResetContext call * Disposable wrapper * Success flag in ctor to dispose * Rename variable name to _autoReleasePool * Abstraction over AutoReleasePool * Use Interlocked.Exchange in AutoReleasePool --------- Co-authored-by: Julien Lebosquain <julien@lebosquain.net>release/latest
committed by
Julien Lebosquain
2 changed files with 59 additions and 7 deletions
@ -0,0 +1,30 @@ |
|||
using System; |
|||
using System.Runtime.InteropServices; |
|||
using System.Threading; |
|||
|
|||
namespace Avalonia.Skia.Metal; |
|||
|
|||
internal sealed partial class AutoReleasePool : IDisposable |
|||
{ |
|||
private IntPtr _pool; |
|||
|
|||
public AutoReleasePool() |
|||
{ |
|||
_pool = Push(); |
|||
} |
|||
|
|||
public void Dispose() |
|||
{ |
|||
var pool = Interlocked.Exchange(ref _pool, IntPtr.Zero); |
|||
if (pool != IntPtr.Zero) |
|||
{ |
|||
Pop(pool); |
|||
} |
|||
} |
|||
|
|||
[LibraryImport("libobjc", EntryPoint = "objc_autoreleasePoolPush")] |
|||
private static partial IntPtr Push(); |
|||
|
|||
[LibraryImport("libobjc", EntryPoint = "objc_autoreleasePoolPop")] |
|||
private static partial void Pop(IntPtr pool); |
|||
} |
|||
Loading…
Reference in new issue