aJson Library - null strings returned.

Hi to everyone.
I'm having troubles with aJson library and an Arduino Mega 2560.
I'll try to explain, here is the code:

void loop()   
{
aJsonObject* sensorType = aJson.createObject();
aJson.addItemToObject(sensorType, "name", aJson.createItem("item"));
if (OpenWriteFile(aJson.print(sensorType))){    
	        counter++;
		Serial.print(counter);
		Serial.print(aJson.print(sensorType));/////
                Serial.println("SD writing OK");
		}
		else
	{
		Serial.println("SD writing error");
	}
}

//---------------------------------------------------------------------
boolean OpenWriteFile(String s_datastring) 
{
	//char name[] = "datalog.txt";
	if (file.open("datalog.txt", O_CREAT | O_APPEND | O_WRITE)){
		delay(500);
		file.println(s_datastring);
		delay(500);
		if (file.writeError) {
			Serial.println("err file writing");
			}
		if (!file.close()) {
			Serial.println("err closing");
			}
	return true;
	}
	else
	{
	return false;
	}
}

It works ok for the first 12 times, then in teturns an empty json object.
I think it gets out of memory, because there are no destructors/garbage colletors, right? Or maybe something else is wrong in the code?
Please, can comeone help me to sort this out? Thanks.

It works ok for the first 12 times, then in teturns an empty json object.

What returns an empty json object?

Where are you deleting the 1st 12 objects? You can't expect the memory allocated to be available again until you delete the objects.

Thanks for the reply.

The null/empty aJson string is returned by Serial.print(aJson.print(sensorType)); and also in the txt file i write using aJsdon.print(sensortype) as parameter in OpenWriteFile.

I've tried with

aJson.delete(objectname);

but got the same error.

At the moment I deleted everything and I'm writing the jSon string into the file by using

log_string=("{\"DATA\":\"%o\", \"DATA2":\"%d\", \"DATA3\":\"%e\", \"DATA4\":\"%k\"}");
log_string.replace("%o",STRINGTOWRITE);  //and so on for all the values

It works and also give me a slightly smaller code footprint, even if it took me some time for preparing and converting the various values (doubles, datetime etc to write).
I think I'll use aJson library only for retrieving the data to be showed on a graphicval display on the arduino (and also by a windows app I'm writing in .net).
But if in case I'll have to rewrite the code also for aJson objects creation/writing, I hope to find out what's wrong with that code.
Thanks.