Andrew - the way I understand how MEX works (and I could be off) is that by calling the MEX function, you are loading it into memory, and it will remain there until you clear the function or terminate your MATLAB session. You can see this "loaded" function using the inmem function. After calling mains the first time, type the following code in the Command Window
[loadedFncs,loadedMexFncs] = inmem('-completenames');
loadedMexFncs
loadedMexFncs =
'/Applications/MATLAB_R2014a.app/toolbox/matlab/graph2d/private/lineseriesmex.mexmaci64'
'/Users/geoff/Development/matlab/testing/mains.mexmaci64'
So the function is in memory, as is the instance of the CSomeClass class. And when you call mains again, you observe that the iVariable is now 100.
If you want to clear the persistent variable between calls to mains, then you could just clear the function in between the two calls
>> mains
oSC.iVariable = 0
>> clear mains
>> mains
oSC.iVariable = 0
Or you could create your instance of CSomeClass in another manner (for example, as a local variable with the mains function) so that it will not persist between calls to mains.