-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure recorded delegates are not released too early (#141)
The operation cache of libvips could reuse the image after subsequent use, so we need to free the recorded delegates until we are sure that the reference count reaches zero.
- Loading branch information
Showing
7 changed files
with
140 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
namespace NetVips.Samples | ||
{ | ||
using System; | ||
using System.IO; | ||
/*using System.Threading.Tasks;*/ | ||
|
||
public class NewFromStreamRef : ISample | ||
{ | ||
public string Name => "NewFromStream reference test"; | ||
public string Category => "Internal"; | ||
|
||
public const string Filename = "images/equus_quagga.jpg"; | ||
|
||
public void Execute(string[] args) | ||
{ | ||
Cache.Max = 0; | ||
|
||
/*Parallel.For(0, 1000, new ParallelOptions { MaxDegreeOfParallelism = NetVips.Concurrency }, | ||
i => | ||
{*/ | ||
using var stream = File.OpenRead(Filename); | ||
var image = Image.NewFromStream(stream, access: Enums.Access.Sequential); | ||
|
||
using var mutated = image.Mutate(mutable => mutable.Set(GValue.GStrType, "exif-ifd0-XPComment", "This is a test")); | ||
|
||
Console.WriteLine($"Reference count image: {image.RefCount}"); | ||
|
||
// Test to ensure {Read,Seek}Delegate doesn't get disposed | ||
image.Dispose(); | ||
|
||
Console.WriteLine($"Reference count mutated: {mutated.RefCount}"); | ||
|
||
var average = mutated.Avg(); | ||
Console.WriteLine($"Average: {average}"); | ||
/*});*/ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.