Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

moonman239

Cancelled
Original poster
Mar 27, 2009
1,541
32
I have three view controllers. One loads another via pushViewController when a condition is met. The latter controller loads the last controller via pushViewController when a condition is met.
Both the last view controller and the first have a variable named thecount. Because of this, I am getting a Mach-O Linker Error. Here's an excerpt from my error log:

Code:
duplicate symbol _thecount in:
...
ld: 1 duplicate symbol for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

This is leading me to suspect that the view controllers that are displayed prior to the last are retained, which is something I don't want happening.

As I write this, I'm starting to think about using segues instead. The reason I didn't do that is because I don't want animated transitions. I know I can use custom segues, which is exactly what I will do. EDIT: That did not make a difference.
 
Last edited:
A linker duplicate symbol error happens while linking. It doesn't have anything to do with runtime behavior of your app. Retain has nothing to do with it.

You didn't show us the ...
Two view controllers that are not related to one another can have properties or ivars with the same name without this error.

Usually a duplicate symbol error would occur if you have file scope global variables with the same name. If that's what you've done then just rename one of the variables.

If that's not what you've done then you need to post more info. What is the ...?
 
Usually a duplicate symbol error would occur if you have file scope global variables with the same name. If that's what you've done then just rename one of the variables.

I did declare both variables in their respective implementations. I wish iOS would automatically dispose of all variables declared in the implementation of a view controller when I call pushViewController.

EDIT: Anyways, I solved the problem by changing the variable name in the last view controller.
 
I did declare both variables in their respective implementations.
How? Show us.

I wish iOS would automatically dispose of all variables declared in the implementation of a view controller when I call pushViewController.

I think you are confused about memory management / structures if you think something like this is a disadvantage when in fact it's an advantage. Think of pushing view controllers like a stack. Why would you want things lower in the stack destroyed when new variables are pushed onto it? What state are they going to be in when you come back after popping off the stack?
 
How? Show us.



I think you are confused about memory management / structures if you think something like this is a disadvantage when in fact it's an advantage. Think of pushing view controllers like a stack. Why would you want things lower in the stack destroyed when new variables are pushed onto it? What state are they going to be in when you come back after popping off the stack?

Here's the thing. The way my app is, I have no need for the app to consume RAM by storing data from other view controllers. All data the app needs to keep will be stored in a local database.
 
I did declare both variables in their respective implementations. I wish iOS would automatically dispose of all variables declared in the implementation of a view controller when I call pushViewController.

EDIT: Anyways, I solved the problem by changing the variable name in the last view controller.

There is something seriously wrong if having the same name in two different classes causes a duplicate symbol error.

If you have a .h file:

Code:
//header comments

@interface MyVC: UIViewController

{
  //instance variables go here
  int foo;
}

//properties go here

@end

There is a copy of each variable that belongs to each INSTANCE of the MyVC class.

If you have variables in your .m file that are declared outside of the

Code:
@implementation

@end

block, then those are global variables, and will cause the link error you describe. Global variables are bad in almost all cases. Avoid them unless you know why they are bad, and why you need to use one anyway. At this point in your learning, you should probably avoid global variables entirely.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.