---
title: "init(charactersNoCopy:length:freeWhenDone:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/nsstring/init(charactersnocopy:length:freewhendone:)"
---

# init(charactersNoCopy:length:freeWhenDone:)

Returns an initialized NSString object that contains a given number of characters from a given C array of UTF-16 code units.

## Declaration

```swift
convenience init(charactersNoCopy characters: UnsafeMutablePointer<unichar>, length: Int, freeWhenDone freeBuffer: Bool)
```

## Parameters

- `characters`: A C array of UTF-16 code units.
- `length`: The number of characters to use from characters.
- `freeBuffer`: If doc://com.apple.documentation/documentation/Swift/true, the receiver releases the memory with free() when it no longer needs the data; if doc://com.apple.documentation/documentation/Swift/false it won’t.

## Return Value

Return Value An initialized NSString object that contains length characters from characters. The returned object may be different from the original receiver.

## Discussion

Discussion If an error occurs during the creation of the string, then bytes is not freed even if flag is true. In this case, the caller is responsible for freeing the buffer. This allows the caller to continue trying to create a string with the buffer, without having the buffer deallocated.

## See Also

### Creating and Initializing Strings

- [init()](foundation/nsstring/init().md)
- [init(bytes:length:encoding:)](foundation/nsstring/init(bytes:length:encoding:).md)
- [init(bytesNoCopy:length:encoding:freeWhenDone:)](foundation/nsstring/init(bytesnocopy:length:encoding:freewhendone:).md)
- [init(characters:length:)](foundation/nsstring/init(characters:length:).md)
- [init(string:)](foundation/nsstring/init(string:)-210xa.md)
- [init(format:arguments:)](foundation/nsstring/init(format:arguments:).md)
- [init(format:locale:arguments:)](foundation/nsstring/init(format:locale:arguments:).md)
- [init(data:encoding:)](foundation/nsstring/init(data:encoding:).md)
- [localizedUserNotificationString(forKey:arguments:)](foundation/nsstring/localizedusernotificationstring(forkey:arguments:).md)
- [localizedStringWithFormat(_:_:)](foundation/nsstring/localizedstringwithformat(_:_:).md)
- [unichar](foundation/unichar.md)
