Frage

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?

War es hilfreich?

Lösung

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

CGFloat dashLengths[count];

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

Andere Tipps

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

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top