# 03.逃逸闭包和非逃逸闭包

## 逃逸闭包\_@escaping

* 一个接受一个闭包作为参数的函数,如果参数需要在函数结束之后才被调用
* 也就是闭包脱离了函数的作用域

## 非逃逸闭包\_@noescape

* 一个接受一个闭包作为参数的函数,闭包会在函数结束前被调用
* 非逃逸闭包

## 内存管理

* 非逃逸闭包不会存在循环引用,因为在函数作用域内就释放了
* 开发中使用非逃逸闭包有利于内存优化

## 自动逃逸

* 注意
  * 当闭包被当做参数,包裹在其他类型中(元祖/枚举/case/Optional可选型)中会自动逃逸


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ryukiedev.gitbook.io/wiki/swift/tao-yi-bi-bao-he-fei-tao-yi-bi-bao.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
