# Go의 Defer와 Rust의 Drop

> Clean Markdown view of GeekNews topic #5527. Use the original source for factual precision when an external source URL is present.

## Metadata

- GeekNews HTML: [https://news.hada.io/topic?id=5527](https://news.hada.io/topic?id=5527)
- GeekNews Markdown: [https://news.hada.io/topic/5527.md](https://news.hada.io/topic/5527.md)
- Type: news
- Author: [ehlegeth](https://news.hada.io/@ehlegeth)
- Published: 2021-12-10T12:11:48+09:00
- Updated: 2021-12-10T12:11:48+09:00
- Original source: [dev.to](https://dev.to/mark_saward/go-footguns-go-defer-and-rust-drop-17af)
- Points: 2
- Comments: 1

## Topic Body

- 리소스를 자동으로 해제하기 위해서 Go에서는 Defer를 사용할 수 있음

ㅤ→ 하지만, 루프 내에서 리소스가 할당되거나 하는 경우에는 방법이 없는 것은 아니지만 복잡해짐

ㅤ→ 실수할 여지가 항상 있음

- Rust에서는 리소스에 대해 Drop trait을 구현해 리소스를 자동으로 해제할 수 있음

ㅤ→ 루프 등의 경우에도 Defer와 같은 문제가 없고 Defer를 통한 리소스 해제 호출이 필요하지 않음

## Comments



### Comment 7854

- Author: ehlegeth
- Created: 2021-12-10T12:14:37+09:00
- Points: 1

Go에도 try-resource에 대한 제안은 있지만 딱히 신경쓰는 것 같지는 않네요:

https://github.com/golang/go/issues/29120

이런 것을 보면, 리소스의 해제를 다른 모듈 아래로 감추지 않으려고 하는 것은 Go의 철학이기도 한 것 같구요.

https://stackoverflow.com/questions/59044658/golang-resource-ownership-pattern-files-connections-close-ables/59046600#59046600
