C# WPF BitmapSource Memory Leak?

前端 未结 1 852
挽巷
挽巷 2021-02-09 13:30

I\'m developing a BlackJack program which shows a BlackJack Table, cards, etc. The plan is that it\'ll be playing thousands of hands one after another with an automated strategy

1条回答
  •  南方客
    南方客 (楼主)
    2021-02-09 13:44

    So first off, you only have 52 cards. Just create the images up front and keep them around for the life of the application. It is a Black Jack game after all; it is safe to assume that each card will be needed at one point or another.

    That said, there is an issue with creating BitmapSource objects from streams. The byte[] held by the stream is not being freed when the stream is disposed. See my own question here. The only reason I didn't vote to close as a duplicate is because I think you should really just create the cards once and be done with it instead of creating these images 10,000+ times.

    0 讨论(0)
提交回复
热议问题