Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8507869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:59:29+00:00 2026-06-11T02:59:29+00:00

The Apple documentation regarding NSData says NSData and its mutable subclass NSMutableData provide data

  • 0

The Apple documentation regarding NSData says

NSData and its mutable subclass NSMutableData provide data objects, object-oriented wrappers for byte buffers. Data objects let simple allocated buffers (that is, data with no embedded pointers) take on the behavior of Foundation objects.

What do they mean by “embedded pointers”? My understanding is that once you put bytes into it, it has no idea what it is unless you decode it at the application level. Anyone know what they are talking about?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T02:59:31+00:00Added an answer on June 11, 2026 at 2:59 am

    The purpose of NSData is to provide a means to cleanup an allocated data buffer when it is no longer needed, i.e. when the reference count of NSData goes to 0. In the common case, the data is allocated with malloc and NSData uses a corresponding call to free to deallocate the data. This places a restriction on the nature of the byte data. It must be Plain Old Data. If the data was a struct containing a field which pointed to another region of memory allocated with malloc (an embedded pointer), the embedded pointer would never be freed by the NSData object, resulting in a memory leak. For example:

    typedef struct Point {
        CGFloat x,
        CGFloat y
    } Point;
    
    typedef struct LineSegment {
        Point* start;
        Point* end;
    } LineSegment;
    
    // point does not contain any embedded pointers (i.e., it is Plain Old Data)
    Point* point = malloc(sizeof(Point));
    // pointData will call free on point to deallocate the memory allocated by malloc
    NSData* pointData = [NSData dataWithBytesNoCopy:point length:sizeof(Point)];
    
    Point* start = malloc(sizeof(Point));
    Point* end = malloc(sizeof(Point));
    
    // line contains two embedded pointers to start and end. Calling free on line
    // without calling free on start and end will leak start and end 
    LineSegment* line = malloc(sizeof(LineSegment));
    line->start = start;
    line->end = end;
    
    // start and end will be leaked!
    NSData* lineData = [NSData dataWithBytesNoCopy:&line length:sizeof(LineSegment)];
    
    // Try this instead. Line is now Plain Old Data
    typedef struct Line {
        Point start;
        Point end;
    } Line;
    
    // anotherLine does not contain any embedded pointers and can safely be used with
    // NSData. A single call to free will deallocate all memory allocated for anotherLine
    // with malloc
    Line* anotherLine = malloc(sizeof(Line));
    
    NSData* anotherLineData = [NSData dataWithBytesNoCopy:&anotherLine
                                                   length:sizeof(Line)];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is a snippet of the official Apple Documentation of AudioBufferList (Core Audio Data
I have read the Apple documentation regarding Mobile Device Management (MDM) but did not
According to Apple's documentation on the View Controller Lifecycle I noticed the following regarding
I'm looking for Apple documentation regarding the delegate and datasource methods for NSTableView. They
The Apple documentation gives the following warning regarding using View Controllers to manage part
Can Someone explain me few things regarding the Singleton implementation in Apple's documentation here.
I'm reading the Core Data Utility tutorial from apple documentation and there's a part
Regarding the Apple documentation there is no way to handle the phone state while
I have a question regarding the code found in the Apple documentation Moving content
I was reading the apple documentation for memory management , and came across something

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.