Your problem is retrieving 3m records at once, this will most likely cause a heapspace regardless of what you do elsewhere. You should consider using using a limit and offset in your: Core.retrieveXPathQueryEscaped statement.
For example, instead of:
List<IMendixObject> lijst = Core.retrieveXPathQueryEscaped(getContext(), "//%s[%s='%s']", entityName1, relationName, objectID);
if (!lijst.isEmpty())
{
for (final IMendixObject object : lijst)
{
batch.removeObject(object);
}
batch.commit();
lijst.clear();
}
Do this:
int limit = 5000;
int offset = 0;
HashMap<String, String> sortMap = new HashMap<String, String>();
sortMap.put("id", "asc");
int count = 0;
int depth = 0;
do {
List<IMendixObject> lijst = Core.retrieveXPathQueryEscaped(getContext(), "//%s[%s='%s']", limit, offset, sortMap, depth, entityName1, relationName, objectID);
count = lijst.size();
for (final IMendixObject object : lijst)
{
batch.removeObject(object);
}
batch.commit();
lijst.clear();
} while (count == limit);
Thanks Jaap, but I get this error:
The method retrieveXPathQueryEscaped(IContext, String, int, int, Map<String,String>, int, String...) in the type Core is not applicable for the arguments (IContext, String, int, int, HashMap<String,String>, String, String, String)
Could this be that this error is because this code needs to work in 2.5.6?