這是這個問題出內存異常+分析HPROF文件的轉儲
java.lang.OutOfMemoryError at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
我創建轉儲文件的問題有關..它給出以下信息
One instance of "byte[]" loaded by "<system class loader>" occupies 1,10,59,216
(51.02%) bytes. The memory is accumulated in one instance of "byte[]"
loaded by "<system class loader>".
Keywords byte[]
所以現在可以做些什麼?我如何清除問題?
我list_objects [背景] -inbound文件
CLASS NAME SHALLOW HEAP RETAINED HEAP
byte[11059200] @ 0xb4979590 | 1,10,59,216 | 1,10,59,216
mBuffer android.graphics.Bitmap @ 0xb3dc68d8 |48 | 48
mBitmap android.graphics.drawable.BitmapDrawable @ 0xb3dbba60 | 72 | 144
mBackground android.widget.RelativeLayout @ 0xb3db3fc0 |512 | 10,144
mBitmap android.graphics.drawable.BitmapDrawable$BitmapState @ 0xb3dc0068 |40 | 40
mBitmapState android.graphics.drawable.BitmapDrawable @ 0xb3dbba60 |72 | 144
referent java.lang.ref.WeakReference @ 0xb3dc2d68 |24 | 24
請幫助我絕望。我如何解決內存問題?
我home_screen.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home_page);
main();
private void main() {
// TODO Auto-generated method stub
final Button home;
final Button aboutus;
final Button contacts;
final Button clients;
final Button services;
try
{
home = (Button)findViewById(R.id.btnHome);
aboutus = (Button)findViewById(R.id.btnAboutus);
clients = (Button)findViewById(R.id.btnClients);
contacts = (Button)findViewById(R.id.btnContacts);
services = (Button)findViewById(R.id.btnServices);
home.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Bitmap b = BitmapFactory.decodeResource(getResources(),R.drawable.home1);
Drawable d = new BitmapDrawable(getResources(),b);
home.setBackgroundDrawable(d);
System.gc();
Intent myIntent = new Intent(Home_Screen.this, Button_Anime.class);
startActivity(myIntent);
}
});
aboutus.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Bitmap b = BitmapFactory.decodeResource(getResources(),R.drawable.about1);
Drawable d = new BitmapDrawable(getResources(),b);
aboutus.setBackgroundDrawable(d);
Intent myIntent = new Intent(Home_Screen.this, AboutUs.class);
startActivity(myIntent);
}
});
clients.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Bitmap b = BitmapFactory.decodeResource(getResources(),R.drawable.clients1);
Drawable d = new BitmapDrawable(getResources(),b);
clients.setBackgroundDrawable(d);
Intent myIntent = new Intent(Home_Screen.this, Clients.class);
startActivity(myIntent);
}
});
contacts.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Bitmap b = BitmapFactory.decodeResource(getResources(),R.drawable.contact1);
Drawable d = new BitmapDrawable(getResources(),b);
contacts.setBackgroundDrawable(d);
Intent myIntent = new Intent(Home_Screen.this, Contacts.class);
startActivity(myIntent);
}
});
services.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Bitmap b = BitmapFactory.decodeResource(getResources(),R.drawable.services1);
Drawable d = new BitmapDrawable(getResources(),b);
services.setBackgroundDrawable(d);
Intent myIntent = new Intent(Home_Screen.this, Services.class);
startActivity(myIntent);
}
});
}
catch(Exception e)
{
e.printStackTrace();
}
}
粘貼您的code.so,我們將分析。 – Dev
@DevCarlsberg我已經發布了我的主文件..請檢查.. – user3214173
老兄經歷[我的這個答案](http://stackoverflow.com/questions/24156047/android-binary-xml-exception-when-changing-pictures/24157195#24157195)會幫助你。 – Dev