CL_MEM_OBJECT_ALLOCATION_FAILURE error after running for some iterations?

Hi all,
I am writing a program that decodes an image(png image). It has 4 filters used for compression which are again used in reverse order to regain the original data.
I when I am executing it, its gets executed for some 150 times and then it throws an error -4 that is CL_MEM_OBJECT_ALLOCATION_FAILURE error. Practically I have no idea
how to remove this error because the same code is getting executed for some 150 times , so I guess the code is correct but there is some runtime problem.
it will be of great help if you can give me a hint of what may cause this error in run time.

thanks,
Piyush