ios - Variables in header file, memory management -
in ios, if put const variables in header file use them in different source files including header file, what's lifecycle of these variables? when these variables allocated/released? these variables stored?
you asked:
what's lifecycle of these variables?
the lifecycle of globals life of app.
when these variables allocated/released?
they're not released until app terminated.
where these variables stored?
if you're talking primitive data types or string literals, they're stored in dedicated __data
segment, not in heap, not in stack.
you should not put implementation of const
globals in header. put them in .m
file. put external references them in .h
file.
so, example, put following in .m
file:
nsstring * const knotificationname = @"com.domain.app.notification";
and then, in .h
file, put:
extern nsstring * const knotificationname;
that way, implement once, files import header have visibility it.
Comments
Post a Comment