Simple WPF sample causes uncontrolled memory growth

后端 未结 4 818
天命终不由人
天命终不由人 2021-02-02 16:49

I have boiled down an issue I\'m seeing in one of my applications to an incredibly simple reproduction sample. I need to know if there\'s something amiss or something I\'m missi

4条回答
  •  不要未来只要你来
    2021-02-02 17:35

    Normally in .NET GC gets triggered on object allocation upon crossing a certain threshold, it does not depend on message pumps (I can't imagine it's different with WPF).

    I suspect that Canvas objects are somehow rooted deep inside or something. If you do c.Children.Clear() right before the BuildCanvas method finishes, the memory growth slows down dramatically.

    Anyway, as a commenter noted here, such usage of framework elements is pretty unusual. Why do you need so many Canvases?

提交回复
热议问题