<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSData/dataWithBytesNoCopy:length:freeWhenDone:",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSData(cm)dataWithBytesNoCopy:length:freeWhenDone:"
  },
  "title" : "dataWithBytesNoCopy:length:freeWhenDone:"
}
-->

# dataWithBytesNoCopy:length:freeWhenDone:

Creates a data object that holds a given number of bytes from a given buffer.

```
+ (instancetype) dataWithBytesNoCopy:(void *) bytes length:(NSUInteger) length freeWhenDone:(BOOL) b;
```

## Parameters

`bytes`

A buffer containing data for the new object. If `freeWhenDone` is <doc://com.apple.documentation/documentation/Swift/true>, `bytes` must point to a memory block allocated with `malloc`.

`length`

The number of bytes to hold from `bytes`. This value must not exceed the length of `bytes`.

`b`

If <doc://com.apple.documentation/documentation/Swift/true>, the returned object takes ownership of the `bytes` pointer and frees it on deallocation.

---

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)