Android文字转语音(TextToSpeech)内存泄漏的问题

在Android项目中,使用Service与Messenger通信进行文字转语音操作时遇到内存泄漏问题。尽管每次创建TextToSpeech实例后调用shutDown方法,仍然报错并影响语音播报。问题解决在于将构造器中的Context由‘this’更改为‘getApplicationContext()’,避免了与Service生命周期相关的问题。内存泄漏的具体原因尚待进一步研究。
摘要由CSDN通过智能技术生成

近期在项目中使用文字转语音遇到一个小问题。项目中是在service中持有一个 TextToSpeech对象,通过messenger与service通信进行文字转语音的操作。但是每次推出应用不久就出出现内存泄漏的问题,如下:

Service com.lucis.workout.service.PrivateSoundService has leaked ServiceConnection android.speech.tts.TextToSpeech$Connection@bf84811 that was originally bound here
                                                                 android.app.ServiceConnectionLeaked: Service com.lucis.workout.service.PrivateSoundService has leaked ServiceConnection android.speech.tts.TextToSpeech$Connection@bf84811 that was originally bound here
                                                                     at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:1344)
                                                                     at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:1239)
                                                                     at android.app.ContextImpl.bindServ
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值