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

每次执行可能不同的动画,都需要重新new,缓存动画的配置参数就无法使用,否则就会有内存无法释放,有没有好的解决办法 #97

Open
hammy-Y opened this issue Jul 25, 2024 · 0 comments

Comments

@hammy-Y
Copy link

hammy-Y commented Jul 25, 2024

async loadAndPlaySVGA(url) {
            if (!url) {
                return this.onGiftAnimationEnd();
            }
            try {
                let svgaParser = new Parser();
                let svga = await svgaParser.load(url);

                let svgaPlayer = new Player({
                    container: document.getElementById("svga-gift-container"),
                    loop: 1,
                    isUseIntersectionObserver: true,
                });
                await svgaPlayer.mount(svga);
                //  设置动画结束回调
                svgaPlayer.onEnd = () => {
                    svgaPlayer.clear();
                    svgaParser.destroy();
                    svgaPlayer.destroy();
                    svga = null;
                    svgaParser = null;
                    svgaPlayer = null;
                    this.onGiftAnimationEnd();
                };
                svgaPlayer.start();
            } catch (error) {
                console.error(error);
            }
        },
@hammy-Y hammy-Y changed the title 不销毁的话内存就会一直叠加,销毁的话就需要每次都new,缓存的动画资源就没了 每次执行可能不同的动画,都需要重新new,缓存动画的配置参数就无法使用,否则就会有内存无法释放,有没有好的解决办法 Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant