Java Heap Space error on RecycleBin

Hi,

I have a Wiki with a RecycleBin that results in a Java Heap Space error when I request the “Deleted Documents” page.

With a script I have managed to delete all other documents from the RecycleBin and found the culprit. It is a renamed/moved page.

Since this was a page with 15 attachments accumulating to 50mb+ in attachments I think the issue has to do with that. However there are no DeletedAttachments with the document.

I used code from snippets to delete the other documents.

The following line of code gives a the Java Heap Error
#set($deletedDocuments=$xwiki.getXWiki().getRecycleBinStore().getAllDeletedDocuments($deletedDocumentDoc, $context, true))

I tried to work around the getAllDeletedDocuments command by using the following code

#foreach($document in $documents)
#set($deletedDocumentDoc=$xwiki.getDocument($document).getDocument())
#set($deletedDocumentDocId=$xwiki.getDocument($document).getDocument().getId())
#set($discard=$xwiki.getXWiki().getRecycleBinStore().deleteFromRecycleBin($deletedDocumentDoc, $deletedDocumentDocId, $context, true))

This worked for all documents in the Recyclebin, but not for the one causing the problem.

When trying to delete the document in that way I get:

Failed to execute the [velocity] macro. Cause: [attempt to create delete event with null entity]. Click on this message for details.

Caused by: java.lang.IllegalArgumentException: attempt to create delete event with null entity
	at org.hibernate.event.spi.DeleteEvent.<init>(DeleteEvent.java:31)
	at org.hibernate.internal.SessionImpl.delete(SessionImpl.java:826)
	at org.hibernate.engine.spi.SessionDelegatorBaseImpl.delete(SessionDelegatorBaseImpl.java:915)
	at com.xpn.xwiki.store.XWikiHibernateRecycleBinStore.lambda$deleteFromRecycleBin$4(XWikiHibernateRecycleBinStore.java:425)
	at com.xpn.xwiki.store.XWikiHibernateBaseStore.execute(XWikiHibernateBaseStore.java:820)
	... 214 more

Both DocumentDoc and DocumentDocID get values.

Anyone a suggestion on how to solve this issue and clean the recycle bin completely.

With kind regards.
Jurjen

Additional,

I am able to reproduce this locally and solve it by adding memory to the JVM.

I wonder if there are options to solve this with scripting without a reboot of the farm.

Regards
Jurjen