GPU- clear variable after use

How do i clear all the variables, that are stored in GPU via cuda programming,after its use, so that memory can be effectively managed

You can try this snippet:

import gc
gc.collect()

with torch.no_grad():
    torch.cuda.empty_cache()

and read: