Project

Profile

Help

Revision 146cfacb

Added by O'Neil Delpratt 5 months ago

Saxon/C memory management patches

View differences:

src/main/c/Saxon.C.API/XdmValue.cpp
126 126

  
127 127

  
128 128
XdmValue::~XdmValue() {
129
	bool safeToClear = false;
129
	//bool safeToClear = false;
130 130
	std::cout<<"xdmValue destructor size= "<<values.size()<<" ref="<<getRefCount()<<std::endl;
131
    if(getRefCount()<1){
132
        std::cout<<"xdmValue destructor refCount="<<getRefCount()<<" values.size="<<values.size()<<std::endl;
131
    //if(getRefCount()<1){
132
    std::cout<<"xdmValue destructor refCount="<<getRefCount()<<" values.size="<<values.size()<<std::endl;
133 133
	//proc->env->ReleaseObject
134
	for (size_t i = 0; i < values.size(); i++) {
135
	    values[i]->decrementRefCount();
136
        std::cout<<"xdmItem (XdmValue destructor) refCount="<<values[i]->getRefCount()<<std::endl;
137
		if (values[i] != nullptr && values[i]->getRefCount() < 1) {
138
			delete values[i];
139
			safeToClear = true;
140
		} else {
141
			safeToClear = false;
142
		}
143
	}
144
	if(safeToClear) {
145
		values.clear();
146
	}
134
	if(values.size() > 0) {
135
        for (size_t i = 0; i < values.size(); i++) {
136
            values[i]->decrementRefCount();
137
            std::cout << "xdmItem (XdmValue destructor) refCount=" << values[i]->getRefCount() << std::endl;
138
            if (values[i] != nullptr && values[i]->getRefCount() < 1) {
139
                delete values[i];
140
            }
141
        }
142
        values.clear();
143
    }
147 144
	if (valueType != nullptr) { delete valueType; }
148 145
	if (jValues) {
149
        std::cout<<"xdmValue jni"<<getRefCount()<<std::endl;
146
        std::cout<<"xdmValue (jValues) jni"<<getRefCount()<<std::endl;
150 147
		SaxonProcessor::sxn_environ->env->DeleteLocalRef(jValues);
151 148
	}
152 149
	xdmSize = 0;
153 150

  
154
    }
151
    //}
155 152

  
156 153
    if(!toStringValue.empty()) {
157 154
        toStringValue.clear();

Also available in: Unified diff