Thanks for the reply.
What I see is that the memory preoccupied keeps increasing by increasing the number of hidden units. With 20000 hidden units, it occupies around 3GB memory.
Is there any way to avoid it? I am basically loosing memory required for computation.