corrupt - Clips multiple EnvEval queries invalidate previous result objects? -


i had strange problem solved already. i'm not sure luckily fixed or understand what's going on. have perform query on facts via:

data_object decay_tree_fact_list; std::stringstream clips_query; clips_query << "(find-all-facts ((?f decaytree)) true)"; enveval(clips_environment_, clips_query.str().c_str(), &decay_tree_fact_list); 

then go through list of facts , retrieve needed information. there make "subquery" each of found facts above in following way

data_object spin_quantum_number_fact_list; std::stringstream clips_query; clips_query << "(find-fact ((?f spinquantumnumber)) (= ?f:unique_id "   << spin_quantum_number_unique_id << "))"; enveval(clips_environment_, clips_query.str().c_str(),   &spin_quantum_number_fact_list); 

this works fine first decaytree fact, no matter @ position start, next 1 crashes, because fact address bogus. traced problem down subquery make. did solve problem save decaytree fact addresses in vector , process that. since not find information theory far wanted ask here.

so question quite simple, , be: if perform 2 queries, after each other, retrieved information of first query invalidated call second query?

the enveval function should marked in documentation triggering garbage collection, not. clips internally represents string, integers, floats, , other primitives similar other languages (such java) allow instances of classes such string, integer, , float. these values dynamically created, need subject garbage collection when no longer used. internally clips uses reference counts determine whether these values referenced, when these values returned user's code not possible know if referenced without action user's code.

when call enveval, value returns exempt garbage collection. not exempt next time enveval called. if process value returned or save (i.e. allocate storage string , copy value clips or save fact addresses multifield in array), don't need worry value returned clips being garbage collected subsequent enveval call.

if want execute series of enveval calls (or other clips function may trigger garbage collection) without having worry values being garbage collected, wrap calls within envincrementgclocks/envdecrementgclocks

envincrementgclocks(theenv);    ... calls ... envdecrementgclocks(theenv);   

garbage collection values returned code temporarily disabled while make calls , when finish calling envdecrementgclocks values garbage collected.

there's additional information on garbage collection in section 1.4 of advanced programming guide.


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -