Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make countUpTimerhandler static to prevent memory leak. #30

Open
krtkush opened this issue Jan 11, 2018 · 0 comments
Open

Make countUpTimerhandler static to prevent memory leak. #30

krtkush opened this issue Jan 11, 2018 · 0 comments
Assignees
Labels
Milestone

Comments

@krtkush
Copy link
Owner

krtkush commented Jan 11, 2018

https://www.androiddesignpatterns.com/2013/01/inner-class-handler-memory-leak.html

Refer - countUpTimer.java: Line 87

private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            synchronized (CountUpTimer.this) {
                long elapsedTime;

                elapsedTime = SystemClock.elapsedRealtime() - base;

                // If elapsed paused time is not zero, reset them to zero so as to begin tracking
                // any further instances of pause button being tapped on
                if(elapsedPausedTime != 0L){
                    elapsedPausedTime = 0L;
                    pauseStart = 0L;
                    pauseEnd = 0L;
                }

                // If condition set up to hinder onTick callBacks being sent if
                // elapsedTime somehow is more than the duration.
                // Stop the timer if it has run for the required duration.
                if(elapsedTime >= duration) {
                    stop();
                } else {
                    onTick(elapsedTime);
                    sendMessageDelayed(obtainMessage(MSG), interval);
                }
            }
        }
    };
@krtkush krtkush added the bug label Jan 11, 2018
@krtkush krtkush added this to the v3.0.0 milestone Jan 11, 2018
@krtkush krtkush self-assigned this Jan 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant