Bug? or bad code?

I have written this function:

    var callTdServer = function(data, onRetryCallBack, maxNumerOfRetry) {
        if (!maxNumerOfRetry) {
            maxNumerOfRetry = 1000000;
        var deferred = $q.defer();
        var counter = 0;

        var httpPromise = $http(data);

        var successCallback = function(response) {
        var errorCallback = function(response) {
            if (counter < maxNumerOfRetry) {
                if (onRetryCallBack) {
                $timeout(function() {
                    $http(data).then(successCallback, errorCallback);
                }, 1000);
            } else {

        httpPromise.then(successCallback, errorCallback);

        return deferred.promise;

I am calling the function like this:

 var showLoading =  function (counter) {
        template: counter+ "<br><ion-spinner></ion-spinner>"

var hideLoading = function(){

var httpPromise = callTdServer(data,  showLoading(counter),10000).then(hideLoading, hideLoading); 

What it does it that it tries to call my server, if it does not succeed (because the server is down or the internet of the phone is off or whatever reason) it will call the “showloading” function with a counter to display the user that we are attempting to call the server.

The problem that I have is that in the beginning it works very good. But if you let your phone for a long time (around 1000 seconds), I see the spinner lag and the CPU used by the app increases. If you let the app run for the night it’s cannot even move…
is it a bug or did I code something really wrong?
just for info I am testing on android 4.4.4 moto G.

thanks in advance.

(please do not tell me something like: you should try to check if the connectivity status of the mobile changes… blablabla, I am asking the question because I do not see anything wrong in the code and Have performance issues because of it).

Some opinion would be nice…