Skip to content

Commit

Permalink
fix(android): prevent layout helper queue hold too many objects
Browse files Browse the repository at this point in the history
  • Loading branch information
iPel committed Dec 7, 2023
1 parent dd29982 commit 25cfe34
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@
import com.tencent.mtt.hippy.common.HippyHandlerThread;
import com.tencent.mtt.hippy.common.HippyThreadRunnable;
import com.tencent.mtt.hippy.utils.LogUtils;
import java.util.concurrent.atomic.AtomicInteger;

@SuppressWarnings({"unused"})
public class LayoutHelper {

private static final int MAX_QUEUE_SIZE = 200;
private HippyHandlerThread mHandlerThread;
private final Picture mPicture = new Picture();
private final AtomicInteger mQueueSize = new AtomicInteger(0);

public LayoutHelper() {
mHandlerThread = new HippyHandlerThread("text-warm-thread");
Expand All @@ -43,11 +46,13 @@ public void release() {
}

public void postWarmLayout(Layout layout) {
if (mHandlerThread != null && mHandlerThread.isThreadAlive()) {
if (mHandlerThread != null && mHandlerThread.isThreadAlive() && mQueueSize.get() < MAX_QUEUE_SIZE) {
mQueueSize.getAndIncrement();
mHandlerThread.runOnQueue(new HippyThreadRunnable<Layout>(layout) {
@Override
public void run(Layout param) {
warmUpLayout(param);
mQueueSize.getAndDecrement();
}
});
}
Expand Down

0 comments on commit 25cfe34

Please sign in to comment.