开发者

GC Collection problem

I am converting a byte array into a BitmapSource. My routine works, I can put a breakpoint on "return dest;" see the value and it's properties for a few seconds and then it times out and I can't access any more properties. Is this getting GC'd? Any ideas how to fix this?

    public static class ImageConversion
{
    public static BitmapSource ConvertByteArrayToBitmapSource(Byte[] imageBytes, ImageFormat formatOfImage)
    {
        BitmapSource dest;
        using (var stream = new MemoryStream())
        {
            stream.Write(imageBytes,0,imageBytes.Length);
            var decoder = new TiffBitmapDecoder(stream, BitmapCrea开发者_开发知识库teOptions.PreservePixelFormat, BitmapCacheOption.Default);
            dest = decoder.Frames[0];
        }

        return dest;
    } }


The memory referenced by dest won't get garbage collected until it's unrooted. As long as you have some variable referencing that memory (including the dest variable itself) it won't get collected.

This is more likely a debugger issue, not a GC issue.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜