Project

Profile

Help

Revision a69dd173

Added by O'Neil Delpratt 6 months ago

Saxon/C update

View differences:

src/main/c/Saxon.C.API/XdmValue.cpp
9 9
XdmValue::XdmValue(const XdmValue &other) {
10 10
	//SaxonProcessor *proc = other.proc; //TODO
11 11
	valueType = other.valueType;
12
	refCount = 1;
12
	refCount = 0;
13 13
	xdmSize = other.xdmSize;
14 14
	jValues = other.jValues;
15 15
	toStringValue = other.toStringValue;
......
62 62

  
63 63
XdmValue::XdmValue(jobject val) {
64 64
	XdmItem * value = new XdmItem(val);
65
	values.resize(0);//TODO memory issue might occur here
65
	values.resize(0);//TODO memory issue might occur here. Need to delete XdmItems
66 66
	values.push_back(value);
67 67
	xdmSize++;
68 68
	jValues = nullptr;
......
127 127

  
128 128
XdmValue::~XdmValue() {
129 129
	bool safeToClear = false;
130
	std::cout<<"xdmValue destructor size= "<<values.size()<<" ref="<<getRefCount()<<std::endl;
130 131
    if(getRefCount()<1){
132
        std::cout<<"xdmValue destructor refCount="<<getRefCount()<<" values.size="<<values.size()<<std::endl;
131 133
	//proc->env->ReleaseObject
132 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;
133 137
		if (values[i] != nullptr && values[i]->getRefCount() < 1) {
134 138
			delete values[i];
135 139
			safeToClear = true;
......
142 146
	}
143 147
	if (valueType != nullptr) { delete valueType; }
144 148
	if (jValues) {
149
        std::cout<<"xdmValue jni"<<getRefCount()<<std::endl;
145 150
		SaxonProcessor::sxn_environ->env->DeleteLocalRef(jValues);  //TODO check - this maybe should be DeleteGlobalRef  - check where it is created
146 151
	}
147 152
	xdmSize = 0;
148
	if(!toStringValue.empty()) {
149
		toStringValue.clear();
150
	}
153

  
154
    }
155

  
156
    if(!toStringValue.empty()) {
157
        toStringValue.clear();
151 158
    }
159
    std::cout<<"end - xdmValue destructor refCount="<<getRefCount()<<std::endl;
152 160

  
153 161
}
154 162

  
155 163
void XdmValue::addXdmItem(XdmItem* val) {
156 164
	if (val != nullptr) {
157 165
		values.push_back(val);
166
        val->incrementRefCount();
158 167
		xdmSize++;
159 168
		jValues = nullptr; //TODO clear jni array from memory if needed
160 169
	}
......
163 172

  
164 173
void XdmValue::addUnderlyingValue(jobject val) {
165 174
	XdmItem * valuei = new XdmItem(val);
175
	valuei->incrementRefCount();
166 176
	values.push_back(valuei);
167 177
	xdmSize++;
168 178
	jValues = nullptr; //TODO clear jni array from memory if needed
......
171 181

  
172 182
void XdmValue::incrementRefCount() {
173 183
		refCount++;
174
		//std::cerr<<"refCount-inc-xdmVal="<<refCount<<" ob ref="<<(this)<<std::endl;
184
		std::cerr<<"refCount-inc-xdmVal="<<refCount<<" ob ref="<<(this)<<std::endl;
175 185
	}
176 186

  
177 187
void XdmValue::decrementRefCount() {
178 188
		if (refCount > 0)
179 189
			refCount--;
180
		//std::cerr<<"refCount-dec-xdmVal="<<refCount<<" ob ref="<<(this)<<std::endl;
190
		std::cerr<<"refCount-dec-xdmVal="<<refCount<<" ob ref="<<(this)<<std::endl;
181 191
	}
182 192

  
183 193

  

Also available in: Unified diff