---
title: "dataWithBytesNoCopy:length:freeWhenDone:"
framework: foundation
role: symbol
role_heading: Type Method
path: "foundation/nsdata/datawithbytesnocopy:length:freewhendone:"
---

# dataWithBytesNoCopy:length:freeWhenDone:

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

## Declaration

```occ
+ (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.

## See Also

### Creating Data

- [data](foundation/nsdata/data.md)
- [dataWithBytes:length:](foundation/nsdata/datawithbytes:length:.md)
- [dataWithBytesNoCopy:length:](foundation/nsdata/datawithbytesnocopy:length:.md)
- [dataWithData:](foundation/nsdata/datawithdata:.md)
- [init(bytes:length:)](foundation/nsdata/init(bytes:length:).md)
- [init(bytesNoCopy:length:)](foundation/nsdata/init(bytesnocopy:length:).md)
- [init(bytesNoCopy:length:deallocator:)](foundation/nsdata/init(bytesnocopy:length:deallocator:).md)
- [init(bytesNoCopy:length:freeWhenDone:)](foundation/nsdata/init(bytesnocopy:length:freewhendone:).md)
- [init(data:)](foundation/nsdata/init(data:).md)
