When one wraps a std::vector using std_vector.i, getting an item by index returns a reference to the element in the vector instead of a copy.
This leads to dandling references if the vector is garbage collected.
For instance, in the following example
in the .i:
in the .py
vector = XVector([X(0), X(1))
element = vector
myelement = toto()
myelement points to a freed element, thus its value is random.
This example can be found there : https://gist.github.com/1985700
The problem was raised on swig-user too:
The first thread provides a workaround, using a typemap.