You have several good answers here; Konstantin points out your bug. Andrei points out the problem with generating large numbers of objects in a loop without draining the autorelease pool. But you should also evaluate your code and make sure you really mean to do this. In the code above, you're busy waiting, which means that you're eating a lot of battery. There are much less power-intensive ways to wait. The easiest is NSTimer. Perhaps this is simplified code to show a point, but generating "now" objects in a loop is probably wrong.
–
Rob NapierJun 10 '11 at 12:52

@Rob: I know but do you think that NSTimer will work with PerformSelectorInBackground ??
–
WasimJun 10 '11 at 19:08

I don't understand the question. Just because you're running "in the background" doesn't mean you can busy-wait. It eats the same amount of CPU on any thread. What problem are you solving here? NSTimer works on any thread that processes its run loop.
–
Rob NapierJun 10 '11 at 19:13

as far as my research on background thereading is concerned, i never see a single post who approved that NSTimer will work in background thread, it only works on Main thread that is why i am trying to accomplish it with a simple while loop. If you think there is another way to accomplish this loop without using While and NSTimer then kindly share it with us.
–
WasimJun 11 '11 at 6:15

In line NSDate *currentDate = [[NSDate alloc] init]; you create a new object, which you should release. In line currentDate = [NSDate date]; you do not release an old object, you only make a pointer to point to another object. In line [currentDate release]; you release an object created on the second line of a loop, which may cause an error (that object is marked as autorelease one and iOS will clean it for you). You should rewrite your code like:

then how will i release it? I read somewhere that NSDate object has no need to be released but when i see Leaks Performance Tool, it shows clearly that a huge amount of memory is leaking. Kindly guide me with this also.
–
WasimJun 10 '11 at 11:19

[NSDate date]; returns an autoreleased object. So you've no need to release the currentDate in my example.
–
EmptyStackJun 10 '11 at 11:24

still the same result, memory is leaking continuously. If i comment the NSDate object then memory leakage is stopped, so its enough cleared that the reason of leakage is the same object.
–
WasimJun 10 '11 at 11:28

@Wasim, I am not sure how the leak occurs. But try my updated answer. It may solve your problem.
–
EmptyStackJun 10 '11 at 11:30

@Wasim, @Simon: the code written by Simon certainly has no memory leaks.
–
Konstantin ChugalinskiyJun 10 '11 at 11:36