From 6b65d8dd9981e9639ad9dd759a57e5403a4773e8 Mon Sep 17 00:00:00 2001 From: Yey007 Date: Tue, 20 Feb 2024 14:47:21 -0500 Subject: [PATCH] Update sample to actually dispose resources --- Samples/RefTypeAnalyzer/Program.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Samples/RefTypeAnalyzer/Program.cs b/Samples/RefTypeAnalyzer/Program.cs index ed18fbb2d..cdc11c154 100644 --- a/Samples/RefTypeAnalyzer/Program.cs +++ b/Samples/RefTypeAnalyzer/Program.cs @@ -17,6 +17,11 @@ public MyUnmanagedType() Hello = 42; } } + + static int AnotherFunction() + { + return new MyRefType().Hello; + } static void Kernel(Index1D index, ArrayView input, ArrayView output) { @@ -30,16 +35,19 @@ static void Kernel(Index1D index, ArrayView input, ArrayView output) // But arrays of reference types are still disallowed MyRefType[] refs = [new MyRefType()]; + + // Any functions that may be called are also analyzed + int result = AnotherFunction(); } static void Main(string[] args) { - var context = Context.CreateDefault(); + using var context = Context.CreateDefault(); var device = context.GetPreferredDevice(false); - var accelerator = device.CreateAccelerator(context); + using var accelerator = device.CreateAccelerator(context); - var input = accelerator.Allocate1D(1024); - var output = accelerator.Allocate1D(1024); + using var input = accelerator.Allocate1D(1024); + using var output = accelerator.Allocate1D(1024); var kernel = accelerator.LoadAutoGroupedStreamKernel, ArrayView>(Kernel);