I have deleted older versions of some documents using web script. Now I want to free space on contentstore being used by deleted versions using web script. Please suggest how it can be achieved.
I think for that you need to have java backed webscript. If you go under your alf_data there you can see the contentstore.deleted folder which keeps all the deleted files. AFIK alfresco service does not provide any API to delete those files. So, you need to write your own code which will delete the respective binaries from that folder.
Using lucene you can try searching for the document in archive store (Never tried!), if you get the node, check if you can get the noderef and then delete it.
Whenever you perform a delete, it goes in trashcan by default. Through API, if you want to delete content permanently then just add temporary aspect(ContentModel.ASPECT_TEMPORARY) to that content before delete action.
Actually Each and every content residing under alfresco follows particular lifecycle. Content in Alfresco> (on deletion) > Archive Store > (after cleaner run)>Deleted from Archivestore but binary file still there in content.deleted folder of alf_data
So, you need to understand this before you do any operation