A call to ContextInstance.deleteVariable(name) does not actually delete the variable from the database. Instead, in the VariableContainer.deleteVariable() method, only the references to the process execution are removed, and a new log entry is added. This can lead to orphaned records in the database.
The applied fix removes the variable instances from the database if the logging service is disabled. With the logging service enabled, the variable cannot be deleted right away, as the new VariableDeleteLog instance holds a reference to the variable. These records will eventually be deleted upon process instance deletion.