I’ve struggling with the memory of my app (alloc, retain, release, etc…) for a while, but there’s something I dont finish to understand.
If I declare this in my .h file:
int ex1;
char ex2[10];
What is the life cycle of these variables? Imagine that I want to use these variables in different parts of my .m code, in methodA I’m going to assign a value, and in methodB I’m going to read them.
Can I be 100% sure that the variables are not going to be released in any moment of my .m?
Thanks
As they are primitives, yes. They will not be retained or released. If you want to declare them as properties, you should declare them as:
and
Then in your .m file
@synthesisethem as normal and you will be able to use[myObject ex1]and[myObject ex2]The idea is really quite simple in Objective C –
Obviously, however these rules apply to pointers to objects, not primitives like int or char.