0

I am setting the line dash style on an NSBezierPath instance:

NSBezierPath *path = [NSBezierPath path];
// Get the path information...

NSInteger count = 0;
// Get the array count...

CGFloat *dashLengths = (CGFloat *)malloc(sizeof(CGFloat) * count);
// Populate the array...

CGFloat phase = 0.0f;
// Get the phase...

[path setLineDash:dashLengths count:count phase:phase];

Should I call free() on dashLengths to prevent a memory leak? Or would releasing the array cause a error later on?

d-squared
  • 107
  • 2
  • 9

3 Answers3

1

Why are you using malloc in the first place? Just declare

CGFloat dashLengths[count];

Now dashLengths is an automatic variable. No memory management required.

matt
  • 515,959
  • 87
  • 875
  • 1,141
0

No, you must free() that malloc()'d array yourself.

trojanfoe
  • 120,358
  • 21
  • 212
  • 242
0

You should call free() on dashLengths right after you free path. NSBezierPath has no way of retaining it, since it's just a regular ol pointer, so you should not take that memory away until NSBezierPath goes away.

escrafford
  • 2,373
  • 16
  • 19