可绘制的内存,它是最好有外APK APK内部资源,或者是相同的内存? [英] memory of drawables, is it better to have resources inside APK, outside APK or is it the same for memory?

查看:144
本文介绍了可绘制的内存,它是最好有外APK APK内部资源,或者是相同的内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有绘制大量的图形,并改变他们的应用程序。
因为我有很多图形,我以为具有APK,根据需要从互联网上下载外的图像,并保存在文件应用程序文件夹。

但我开始OutOfMemory异常。

现在的问题是:是否Android处理内存不同,如果我从加载APK图形比我加载它从磁盘

code。使用APK:


  

    

topView.setBackgroundResource(R.drawable.bg);


  

code,如果图像是APK外:


  

    

绘制对象D = Drawable.createFromPath(将pathName);
    topView.setBackgroundDrawable(D);


  

感谢

丹尼尔


解决方案

没有在内部处理它们的相同。最有可能的,你是泄漏的图像,或不清理它们以最快的速度你可以。尝试调用 Bitmap.recycle(); 一旦你用图像做,迫使Android的把它清理干净。

I have an application that draws a lot of graphics and change them. Since I have many graphics, I thought of having the images outside the APK, downloaded from the internet as needed, and saved on the files application folder.

But I started to get outOfMemory exceptions.

The question is: Does android handle memory different if I load a graphic from APK than if I load it from 'disk'?

code using APK:

topView.setBackgroundResource(R.drawable.bg);

code if image is outside APK:

Drawable d = Drawable.createFromPath(pathName); topView.setBackgroundDrawable(d);

Thanks

Daniel

解决方案

No, internally they are handled the same. Most likely, you're leaking the images, or not cleaning them up as quickly as you could. Try calling Bitmap.recycle(); once you're done with an image, to force Android to clean it up.

这篇关于可绘制的内存,它是最好有外APK APK内部资源,或者是相同的内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆