Since a GLfloat
is a C typedef that has nothing to do with Objective-C you can't retain it by using any Objective-C feature.
The problem in your example is that GLfloat glData[n]
is an array with automatic allocation onto the stack. When the function in which you declared it returns to the caller, the data pointed is no longer valid.
What you should do it managing the memory by yourself:
-(void)loadObj {
(...)
GLfloat *glData = calloc(n, sizeof(GLfloat));
(...) //populate glData array
self.data = glData;
}
In this way you are allocating the array in the heap and it won't become invalid when function exits. Mind that this memory is not managed by Objective-C so you are responsible of releasing it when needed, eg
-(void)dealloc {
free(self.data);
[super dealloc];
}