The cleaner method will delete the x variable from the local scope, not the global one.
To remove the global x, you could use the global keyword:
x = torch.tensor([1., 2.]).cuda() 
print(torch.cuda.memory_allocated()) # 512
del x 
print(torch.cuda.memory_allocated()) # 0

def cleaner():
    global x
    del x

x = torch.tensor([1., 2.]).cuda() 
print(torch.cuda.memory_allocated()) # 512
cleaner()
print(torch.cuda.memory_allocated()) # 0