In the above while loop, if I just leave inside the following two lines:
CDynamicArray<uint32_t>* hashed_indices = new CDynamicArray<uint32_t>();
SG_UNREF(hashed_indices);

I'm getting the following errors, on a multithreaded code : "call init_shogun() before using the library, dying."

So, I'm guessing this rapid creation and unref'ing somehow manages to get things unref'ed when they shouldn't be?