.NET GC & Memory (1)
åå¿è
åãã«ã¯ãã°ãã°ãé©å½ã«ååãã¦ããã¾ããã¨èª¬æããã .NET ã® GC ã§ããï¼å®éã® GC ã¯ç¡ä½çºã«å®è¡ãããã®ã§ã¯ãªãï¼ããã¢ã«ã´ãªãºã ã«å¾ã£ã¦åãã¦ããï¼ãé©å½ãã¨ããè¨èã§ãã©ãã¯ããã¯ã¹æãæ¼åºããã®ã¯ãã¾ã好ãã§ã¯ããã¾ããï¼ã¾ãé©åã§å½ç¶ãªãé©å½ãã ã¨ãã¦ãï¼ä¸æã«å®ã¾ããããããªãã®ã§ãããã¼ããã®ã¯ã¾ããã¨æãããã§ããï¼
以ä¸ã¯ãã¤ããã® GDNJ IDisposable è«äºã§æãããã®*1ãå°ãã ãæ¸ãç´ãããã®ã§ããï¼æå
ã®ç°å¢ãå«ã Visual C# .NET 2003 + .NET Framework 1.1 SP1 ã¨ããæ¡ä»¶ä¸ã§ã¡ãã»ãå®èµ°ããªãç¾è±¡ãåç¾ã§ããããã§ãï¼
using System; using System.Diagnostics; class Program { static void Main(string args) { Trace.Listeners.Add(new TextWriterTraceListener(Console.Out)); int i = 0; try { for (i = 0; i < 1024; ++i) { byte buffer = new Byte[1024 * 1024 * 128]; // ä¸åº¦ã¢ã¯ã»ã¹ãã¦ãããªã㨠C# 2.0 ã®æé©åã³ã³ãã¤ã©ã«ãã£ã¦ // é åã®ä½æãã®ãã®ãé¤å»ããã buffer[0] = 1; } Trace.WriteLine("å®èµ°!"); } catch { Trace.WriteLine(i + " åç®ã§ã¹ããã"); } } }
çæããã 128MB ã®ãããã¡ã¯ï¼ããã«ã«ã¼ãåç
§ããå¤ãã¾ãã®ã§ï¼GC ãå¹ççã«åãã¦ããï¼ãããã¯æ°è¦ã¡ã¢ãªç¢ºä¿æã«ãªã³ããã³ã㧠GC ãè¡ã£ã¦ããã°ï¼æå¾ã¾ã§èµ°ã£ã¦ãããããªãã®ã§ãï¼ãï¼äºæ³ã«åãã¦åãã¦ãããªãã¨ããã®ãæ¬æ°ã¨ããã話ã®ãã¿ã ã£ãããã§ããï¼
GDNJ ã®ã.NET Framework 1.1 ã§æ°åMByte ã®ãã¼ã¿ãæ±ãã¨ã¡ã¢ãªä¸è¶³ã«ãªããããåããããªè©±é¡ãåãä¸ãããã¦ãã¾ãï¼
C++ ã®ããã«ç¢ºå®è«çã«ã¡ã¢ãªã®ç¢ºä¿/解æ¾ãè¡ãã³ã¼ãã C# ã«ç§»æ¤ããéã«ãã®ãããªåé¡ã表é¢åããå¯è½æ§ãããï¼ãã¾ããããããªãæ¯ãèãã§ãï¼
ä¸æ¹ï¼Visual C# 2005 + .NET 2.0 ã§ã¯ä¸è¨ã³ã¼ãã¯åé¡ãªãå®èµ°ããããã«ãªãã¾ããï¼ã¨æ¸ãã¨åç´ã«ããã¾ã§ã®è©±ã®ããã«è¦ãã¾ããï¼å®éã«ã¯ .NET 1.1 SP1 ã§ã Server GC ã使ç¨ããã¨å®èµ°ããå¯è½æ§ãé«ãããããªããã¨æãã¾ãï¼å°ãªãã¨ãæå
ã®ç°å¢ã§ã¯å®èµ°ãã¦ããã¾ãï¼App.config ã«ãããªæãï¼
<?xml version="1.0" encoding="utf-8" ?> <configuration> <runtime> <gcServer enabled="true" /> </runtime> </configuration>
ã¨ããããã§ï¼ä½ãè¨ããããã¨ããã¨ï¼ããã¨ããã¨ãã®ããã«ãã©ãã¯ããã¯ã¹ã®ä¸ãããã¦åä½ã調ã¹ã¦ã¿ãæ¹æ³ãç¥ã£ã¦ãããæ¹ãããããããªãã§ãããï¼ ã¨ï¼ã¾ãå
¨å¡ãç¥ã£ã¦ããå¿
è¦ã¯ãªãã¨æãã¾ããï¼ããã³ãã¥ããã£å
ã§ç¹å®æè¡ã®ãã©ãã¯ããã¯ã¹çãä¸å®å¤ãè¶
ããã¨ãã£ã±ãå°ã£ãç¶æ
ã«é¥ããããã®ã§ã¯ãªããã¨æãã¾ãï¼é¾å¤ã¯ã¾ãã±ã¼ã¹ãã¤ã±ã¼ã¹ã§ããããã©ãï¼
CLR ã®å ´å㯠Hosting API ã§è²ã
ä¸ã«æ½ããã¨ãã§ããã®ã§ï¼ãã®è¾ºã«ã¤ãã¦ããå°ãæ¸ãã¦ãããæ¹ãå¾ã
楽ã«ãªãããªã¨æã£ã次第ã§ãï¼
*1:http://www.gdncom.jp/general/bbs/ShowPost.aspx?PostID=4718&PageIndex=10#5934