<!--
{
  "documentType" : "article",
  "framework" : "Xcode",
  "identifier" : "/documentation/Xcode/deallocation-of-nonallocated-memory",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Deallocation of nonallocated memory"
}
-->

# Deallocation of nonallocated memory

Detects attempts to free nonallocated memory.

## Overview

Use this check to detect when you call `free` on memory that you don’t allocate using `malloc`. Attempting to deallocate nonallocated memory can result in a crash. Available in Xcode 7 and later.

### Deallocation of a stack variable in C

In the following example, the `value` variable allocates on the stack, and deallocates when the function exits, so calling `free` on it is incorrect:

```occ
int value = 42;
free(&value); // Error: free called on stack allocated variable
```

#### Solution

Don’t call the `free` function on variables that you allocate on the stack.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)