{"id":1168,"date":"2019-12-04T14:32:08","date_gmt":"2019-12-04T05:32:08","guid":{"rendered":"http:\/\/yoonhada.com\/wp\/?p=1168"},"modified":"2023-12-27T00:58:07","modified_gmt":"2023-12-26T15:58:07","slug":"idisposable","status":"publish","type":"post","link":"http:\/\/yoonhada.com\/?p=1168","title":{"rendered":"Unity C# \u2013 IDisposable \uc54c\uc544\ubcf4\uae30"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\uc774\ubc88\uc5d0\ub294 IDisposable \uc778\ud130\ud398\uc774\uc2a4\uc5d0 \ub300\ud574\uc11c \uc54c\uc544\ubcf4\uaca0\uc2b5\ub2c8\ub2e4. C#\uc740 \uac00\ube44\uc9c0\ucf5c\ub799\ud130(Garbage Collector)\ub97c \uac00\uc9c0\uace0 \uc788\uc2b5\ub2c8\ub2e4. \uc774 GC\ub294 \uae30\ubcf8\uc801\uc73c\ub85c \uad00\ub9ac\ub418\ub294 \ubaa8\ub4e0 \uac1d\uccb4\ub4e4\uc758 \ucc38\uc870 \ub9c1\ud06c\ub97c \uad00\ub9ac\ud558\uba70 \ub354\uc774\uc0c1 \ucc38\uc870\ub418\uc9c0 \uc54a\ub294 \uac1d\uccb4\ub4e4\uc744 \uc790\ub3d9\uc73c\ub85c \uba54\ubaa8\ub9ac\uc5d0\uc11c \uc18c\uac70\ud558\ub294 \uc791\uc5c5\uc744 \uc218\ud589\ud569\ub2c8\ub2e4. \ud558\uc9c0\ub9cc GC\ub294 \ucc3d \ud578\ub4e4, \uc5f4\ub9b0 \ud30c\uc77c, \uc2a4\ud2b8\ub9bc\uacfc \uac19\uc774 \uad00\ub9ac\ub418\uc9c0 \uc54a\ub294 \ub9ac\uc18c\uc2a4\ub4e4\uc744 \uc778\uc2dd\ud558\uc9c0 \ubabb\ud569\ub2c8\ub2e4.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\ub2e4\uc74c\uc740 \ubb38\uc81c\uac00 \ubc1c\uc0dd\ud560 \uac00\ub2a5\uc131\uc774 \uc788\ub294 StreamReader\uc758 \uc0ac\uc6a9 \uc608 \uc785\ub2c8\ub2e4.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">StreamReader reader = new StreamReader(\"content.txt\");\nstring content = reader.ReadToEnd();\n\/\/ content \ud65c\uc6a9 \ucf54\ub4dc \uc218\ud589\nreader.Close();<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\ud558\uc9c0\ub9cc \uc704\uc758 \ucf54\ub4dc\ub294\u00a0ReadToEnd() \uba54\uc18c\ub4dc\ub97c \uc218\ud589\ud558\ub294 \uacfc\uc815\uc5d0\uc11c \uc624\ub958\uac00 \ubc1c\uc0dd\ud560 \uac00\ub2a5\uc131\uc774 \uc788\uc2b5\ub2c8\ub2e4. \uc774\ub54c\uc5d0 Close()\uac00 \ud638\ucd9c\ub418\uc9c0 \uc54a\uace0 \ubc18\ud658\ub420 \uac00\ub2a5\uc131\uc774 \uc788\uc2b5\ub2c8\ub2e4. \uc774\ub7ec\ud55c \ubb38\uc81c\ub97c \ub300\uc751\ud558\uae30 \uc704\ud574 \ud754\ud788\ub4e4 try-catch-finally \uad6c\ubb38\uc744 \uc0ac\uc6a9\ud574 \ubcfc \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">StreamReader reader = new StreamReader(\"content.txt\");\ntry {\n\tstring content = reader.ReadToEnd();\n} catch(IOException e) {\n\tDebug.Log (\"Error: \" + e.Message);\n} finally {\n\treader.Close();\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\uc704\uc758 \ucf54\ub4dc\ub294\u00a0ReadToEnd() \uba54\uc18c\ub4dc\ub97c \uc218\ud589\uc911\uc5d0 \uc608\uc678\uac00 \ubc1c\uc0dd\ub418\uba74 \ubc1c\uc0dd\ud55c \uc608\uc678\uc758 \ub0b4\uc6a9\uc744 \ub85c\uadf8\uc5d0 \ucd9c\ub825\ud558\uac8c \ub429\ub2c8\ub2e4. \uadf8\ub9ac\uace0 \uc608\uc678\uac00 \ubc1c\uc0dd\ud558\uac70\ub098 \uc131\uacf5\ud558\uac70\ub098 \uc0c1\uad00\uc5c6\uc774 Close() \uba54\uc18c\ub4dc\ub97c \uc815\uc0c1\uc801\uc73c\ub85c \uc218\ud589\ud558\uac8c \ub429\ub2c8\ub2e4. \ud558\uc9c0\ub9cc \uc774\ub7ec\ud55c \ubcf5\uc7a1\ud55c \uacfc\uc815 \uc5c6\uc774 Close() \ud638\ucd9c\uc744 \uc54c\uc544\uc11c \ud638\ucd9c\ud574\uc8fc\ub294 \uad6c\ubb38\uc774 \uc788\uc2b5\ub2c8\ub2e4. \uc704\uc640 \uac19\uc740 \ubc29\ubc95\uc774 \uc544\ub2cc using \ube14\ub85d\uc744 \uc0ac\uc6a9\ud558\uc5ec \ub2e4\uc74c\uacfc \uac19\uc774 \ucc98\ub9ac\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">using (StreamReader reader = new StreamReader(\"content.txt\")) {\n\tstring content = reader.ReadToEnd();\n\t\/\/ content \ud65c\uc6a9 \ucf54\ub4dc \uc218\ud589\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\uc704\uc758 \ucf54\ub4dc\uc5d0\uc11c \uc6b0\uc120 \ub208\uc5d0 \ub744\ub294 \uac83\uc740 using \ud0a4\uc6cc\ub4dc\ub97c \uc0ac\uc6a9\ud588\ub2e4\ub294 \uc810\uacfc Close() \ub97c \uba85\uc2dc\uc801\uc73c\ub85c \ud638\ucd9c\ud558\uc9c0 \uc54a\uace0 \uc788\ub2e4\ub294 \ubd80\ubd84\uc785\ub2c8\ub2e4. \uc774\uc81c IDisposable\uc5d0 \ub300\ud574 \uc774\uc57c\uae30\ub97c \ud574\ubcfc \ub54c\uc778 \uac83 \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"885\" height=\"564\" src=\"http:\/\/yoonhada.com\/wp-content\/uploads\/2023\/12\/image.png\" alt=\"\" class=\"wp-image-2113\" srcset=\"http:\/\/yoonhada.com\/wp-content\/uploads\/2023\/12\/image.png 885w, http:\/\/yoonhada.com\/wp-content\/uploads\/2023\/12\/image-300x191.png 300w, http:\/\/yoonhada.com\/wp-content\/uploads\/2023\/12\/image-768x489.png 768w\" sizes=\"auto, (max-width: 885px) 100vw, 885px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">SteamReader\ub294 TextReader\uc758 \uc790\uc2dd \ud074\ub798\uc2a4\uc785\ub2c8\ub2e4. \uadf8\ub9ac\uace0 \uc774 TextReader\ub294 IDisposable \uc778\ud130\ud398\uc774\uc2a4\ub97c \uad6c\ud604\ud558\uace0 \uc788\uc2b5\ub2c8\ub2e4.\u00a0<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"891\" height=\"407\" src=\"http:\/\/yoonhada.com\/wp-content\/uploads\/2023\/12\/image-1.png\" alt=\"\" class=\"wp-image-2114\" srcset=\"http:\/\/yoonhada.com\/wp-content\/uploads\/2023\/12\/image-1.png 891w, http:\/\/yoonhada.com\/wp-content\/uploads\/2023\/12\/image-1-300x137.png 300w, http:\/\/yoonhada.com\/wp-content\/uploads\/2023\/12\/image-1-768x351.png 768w\" sizes=\"auto, (max-width: 891px) 100vw, 891px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"884\" height=\"411\" src=\"http:\/\/yoonhada.com\/wp-content\/uploads\/2023\/12\/image-2.png\" alt=\"\" class=\"wp-image-2115\" srcset=\"http:\/\/yoonhada.com\/wp-content\/uploads\/2023\/12\/image-2.png 884w, http:\/\/yoonhada.com\/wp-content\/uploads\/2023\/12\/image-2-300x139.png 300w, http:\/\/yoonhada.com\/wp-content\/uploads\/2023\/12\/image-2-768x357.png 768w\" sizes=\"auto, (max-width: 884px) 100vw, 884px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\uc774 IDisposable \uc778\ud130\ud398\uc774\uc2a4\ub294 Dispose() \uba54\uc18c\ub4dc \ud558\ub098\ub9cc\uc744 \uac00\uc9c0\uace0 \uc788\ub124\uc694. \uc774 IDisposable \uc778\ud130\ud398\uc774\uc2a4\ub97c \uad6c\ud604\ud55c \ud074\ub798\uc2a4\ub294 Dispose() \ud074\ub798\uc2a4\ub97c \uad6c\ud604\ud574\uc57c \ud558\uba70 \uc5ec\uae30\uc11c \uc790\uc2e0\uc758 \uba54\ubaa8\ub9ac \ud560\ub2f9 \ub0b4\uc5ed\uc744 \uc815\ub9ac\ud574\uc57c \ud569\ub2c8\ub2e4. \uc704\uc5d0\uc11c \ubcf4\uc5ec\uc900 \uc608\uc81c\uc5d0\uc11c \ubcf4\uc5ec\uc9c0\ub294 StreamReader \uc5ed\uc2dc Dispose() \ud074\ub798\uc2a4\ub97c \uad6c\ud604\ud558\uace0 \uc788\uc73c\uba70 \uc5ec\uae30\uc11c \ub9ac\uc18c\uc2a4\ub97c \uc815\ub9ac\ud558\ub294 \uc801\uc808\ud55c \ucc98\ub9ac\uac00 \ub418\uc5b4\uc788\uc744 \uac83\uc785\ub2c8\ub2e4.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">using (IDisposable \uc778\ud130\ud398\uc774\uc2a4\ub97c \uad6c\ud604\ud55c \ud074\ub798\uc2a4 \uc778\uc2a4\ud134\uc2a4 \uc120\uc5b8) {\n    \/\/ \ub9ac\uc18c\uc2a4 \uc815\ub9ac\uac00 \uc815\uc0c1\uc801\uc73c\ub85c \uc774\ub8e8\uc5b4\uc9c0\uc9c0 \uc54a\uc744 \uac00\ub2a5\uc131\uc774 \uc788\ub294 \ucc98\ub9ac\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\uc774\uc81c \uc704\uc758 \ucf54\ub4dc\ub294 IDisposable \uc778\ud130\ud398\uc774\uc2a4\ub97c \uad6c\ud604\ud558\uace0 \uc788\ub294 \ud074\ub798\uc2a4\ub97c \uc778\uc2a4\ud134\uc2a4\ud654 \ud558\uc5ec \uc0ac\uc6a9\ud558\uba70 using \ube14\ub85d\uc744 \ub098\uac00\ub294\uc21c\uac04 (\uc2ec\uc9c0\uc5b4 \uc624\ub958\uac00 \ubc1c\uc0dd\ud558\ub354\ub77c\ub3c4) Dispose() \uac00 \ud638\ucd9c\ub418\uc5b4 \uc0ac\uc6a9\ud55c \ub9ac\uc18c\uc2a4\uac00 \uc790\ub3d9\uc73c\ub85c \uc815\ub9ac\ub429\ub2c8\ub2e4.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\uadf8\ub807\ub2e4\uba74 using \ube14\ub85d \ub0b4\ubd80\uc5d0\uc11c \ubc1c\uc0dd\ud55c \uc608\uc678\ub294 \uc5b4\ub5bb\uac8c \ucc98\ub9ac\ud560 \uc218 \uc788\uc744\uae4c\uc694? \ub2e4\uc74c\uacfc \uac19\uc740 \ubc29\ubc95\uc73c\ub85c \ucc98\ub9ac\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">try {\n\tusing (StreamReader reader = new StreamReader (\"file.txt\")) {\n\t\t\/\/ \ub9ac\uc18c\uc2a4 \uc815\ub9ac\uac00 \uc815\uc0c1\uc801\uc73c\ub85c \uc774\ub8e8\uc5b4\uc9c0\uc9c0 \uc54a\uc744 \uac00\ub2a5\uc131\uc774 \uc788\ub294 \ucc98\ub9ac\n\t}\n} catch(IOException e) {\n\tDebug.Log (\"Error: \" + e.Message);\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">using \ubc14\uae65\ucabd\uc5d0 try-catch \ubb38\uc744 \uc0ac\uc6a9\ud574\ub3c4 using \ube14\ub85d\uc744 \ube60\uc838\ub098\uac08 \ub54c Dispose() \uac00 \ud638\ucd9c\ub429\ub2c8\ub2e4.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\ucc38\uace0 :&nbsp;<a href=\"https:\/\/msdn.microsoft.com\/ko-kr\/library\/system.idisposable(v=vs.110).aspx\">https:\/\/msdn.microsoft.com\/ko-kr\/library\/system.idisposable(v=vs.110).aspx<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\uc774\ubc88\uc5d0\ub294 IDisposable \uc778\ud130\ud398\uc774\uc2a4\uc5d0 \ub300\ud574\uc11c \uc54c\uc544\ubcf4\uaca0\uc2b5\ub2c8\ub2e4. C#\uc740 \uac00\ube44\uc9c0\ucf5c\ub799\ud130(Garbage Collector)\ub97c \uac00\uc9c0\uace0 \uc788\uc2b5\ub2c8\ub2e4. \uc774 GC\ub294 \uae30\ubcf8\uc801\uc73c\ub85c \uad00\ub9ac\ub418\ub294 \ubaa8\ub4e0 \uac1d\uccb4\ub4e4\uc758 \ucc38\uc870 \ub9c1\ud06c\ub97c \uad00\ub9ac\ud558\uba70 \ub354\uc774\uc0c1 \ucc38\uc870\ub418\uc9c0 \uc54a\ub294 \uac1d\uccb4\ub4e4\uc744 \uc790\ub3d9\uc73c\ub85c \uba54\ubaa8\ub9ac\uc5d0\uc11c \uc18c\uac70\ud558\ub294 \uc791\uc5c5\uc744 \uc218\ud589\ud569\ub2c8\ub2e4. \ud558\uc9c0\ub9cc GC\ub294 \ucc3d \ud578\ub4e4, \uc5f4\ub9b0 \ud30c\uc77c, \uc2a4\ud2b8\ub9bc\uacfc \uac19\uc774 \uad00\ub9ac\ub418\uc9c0 \uc54a\ub294 \ub9ac\uc18c\uc2a4\ub4e4\uc744 \uc778\uc2dd\ud558\uc9c0 \ubabb\ud569\ub2c8\ub2e4. \ub2e4\uc74c\uc740 \ubb38\uc81c\uac00 \ubc1c\uc0dd\ud560 \uac00\ub2a5\uc131\uc774 \uc788\ub294 StreamReader\uc758 \uc0ac\uc6a9 \uc608 \uc785\ub2c8\ub2e4. \ud558\uc9c0\ub9cc \uc704\uc758 \ucf54\ub4dc\ub294\u00a0ReadToEnd() \uba54\uc18c\ub4dc\ub97c \uc218\ud589\ud558\ub294 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[80,90],"tags":[64,42],"class_list":["post-1168","post","type-post","status-publish","format-standard","hentry","category-project","category-unity-project","tag-programming","tag-unity"],"_links":{"self":[{"href":"http:\/\/yoonhada.com\/index.php?rest_route=\/wp\/v2\/posts\/1168","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/yoonhada.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/yoonhada.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/yoonhada.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/yoonhada.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1168"}],"version-history":[{"count":3,"href":"http:\/\/yoonhada.com\/index.php?rest_route=\/wp\/v2\/posts\/1168\/revisions"}],"predecessor-version":[{"id":2116,"href":"http:\/\/yoonhada.com\/index.php?rest_route=\/wp\/v2\/posts\/1168\/revisions\/2116"}],"wp:attachment":[{"href":"http:\/\/yoonhada.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1168"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/yoonhada.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1168"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/yoonhada.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}