<!--
{
  "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/init(bytesNoCopy:length:freeWhenDone:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSData(im)initWithBytesNoCopy:length:freeWhenDone:"
  },
  "title" : "init(bytesNoCopy:length:freeWhenDone:)"
}
-->

# init(bytesNoCopy:length:freeWhenDone:)

Initializes a newly allocated data object by adding the given number of bytes from the given buffer.

```
init(bytesNoCopy bytes: UnsafeMutableRawPointer, length: Int, freeWhenDone b: Bool)
```

## Parameters

`bytes`

A buffer containing data for the new object. If `flag` 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.

## See Also

[`dataWithBytesNoCopy:length:freeWhenDone:`](/documentation/Foundation/NSData/dataWithBytesNoCopy:length:freeWhenDone:)

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



---

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)