问题描述
亲爱的CodeProject会员,
我一直面临严重的记忆问题,他们正在推动我的努力。目前我正在制作一款像野味一样的游戏,你可以在这个视频中看到:
[]
我已经能够制作一个完全正常工作的块系统,到目前为止我已经更新了它以便我可以有大约250种不同的块。虽然这不是我的问题所在,但我似乎只是在获得记忆。它让我疯狂,我不知道为什么。这就是我的意思:
http://i49.tinypic.com/2n7f32t.png
我尝试仅使用Paint事件本身的图形进行绘制,但这样的结果与更多内存相同。这是正常还是我严重搞砸了什么?
这是我的一段代码:
Dear CodeProject Members,
I have been facing serious memory issues and they are driving me nutes. Currently I am making a terraria like game, as you can see on this video:
https://www.youtube.com/watch?v=bQ_9m-KkdBQ[^]
I have been able to make a fully working chunk system, and so far have updated it so that I can have about 250 different kind of blocks. Although here is not where my problem lies I seem to be only gaining memory. It''s driving me nuts and I have no idea why. This is what I mean:
http://i49.tinypic.com/2n7f32t.png
I tried drawing only with the graphics from the Paint Event itself but this resulted the same with even more memory. Is this normal or am I seriously messing something up?
Here is my piece of code:
protected override void OnPaint(PaintEventArgs e)
{
// -- Clear.
e.Graphics.Clear(this.BackColor);
// -- Draw on bitmap..
Bitmap _Bitmap = new Bitmap(this.ClientSize.Width, this.ClientSize.Height);
using (Graphics g = Graphics.FromImage(_Bitmap))
{
DrawWorld(g);
DrawPlayer(g);
DrawInformation(g);
}
// -- Draw the Bitmap.
e.Graphics.DrawImage(_Bitmap, 0, 0, this.ClientSize.Width, this.ClientSize.Height);
// -- Dispose the bitmap.
_Bitmap.Dispose();
// -- Flush.
e.Graphics.Flush();
// -- Variables.
GC.Collect();
GC.WaitForPendingFinalizers();
}
有趣的是,即使没有走出第一块,问题仍然会发生,所以这不是一个块错误。我已经检查了100多次。
我还要补充说这个记忆人们告诉我,过了一段时间后它没有下降到它的原始数量。
任何人?救命 ! :L
The funny thing is, is, that without even going out of the first chunk the issue still occurs, so it is not a chunk error. Which I have also checked over 100+ times.
Let me also add that this memory does not drop down to it''s original amount after a while, people told me that.
Anyone ? Help ! :L
推荐答案
这篇关于[C#/绘图]内存问题 - 内存不断上升的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!