Bitmap.getBitmapResource() - 内存问题

时间:2011-02-07 20:19:40

标签: java caching blackberry

我想知道对同一图片多次调用Bitmap.getBitmapResource()是否会导致创建多个Bitmap个实例?或者,每个返回值是否指向同一个内存?官方文档似乎没有太大帮助。我使用这个调用为我的一堆屏幕设置相同的背景图像,所以我应该创建一个缓存来加载到内存中并为每个屏幕返回相同的对象吗?

以下是相关文件:

public static Bitmap getBitmapResource(String name)

    Creates a bitmap from provided name resource.

    This method looks for the resource in both the .cod file that called this method and any .cod files that it relies on. The resource files are automatically generated by the compiler when a new graphic (PNG, GIF, or, JPG) is added to a project.

    Parameters:
        name - Name of the bitmap resource.
    Returns:
        New Bitmap object, or null if this method couldn't find your named resource.
    Throws:
        NullPointerException - If the name parameter is null.
    Since:
        JDE 4.0.2

1 个答案:

答案 0 :(得分:0)

您将为每个调用获取一个新的Bitmap实例。文档实际上在“返回”部分中说:“新的位图对象”......

所以,是的,您应该缓存对象并在屏幕中重复使用它。将位图实例存储在整个应用程序中访问的静态中并不罕见。