如何解决内存溢出以及内存泄漏

前言:

很多人在项目中都遇到过内存溢出问题,其实说白了就是内存不够用了,那么要解决这个问题,我们就需要 “开源节流”了

1.开源(增加内存分配)

每台手机给每个程序分配的内存都是固定的,那么是否有办法使我们的程序获取到更大的内存呢?其实是有的,而且很简单

你只需要在清单文件中的application的节点中加入 android:largeHeap=”true” 即可, 是不是很简单?

<application
      ...
        android:largeHeap="true"
       >

    </application>

但是这样做其实是有弊端的,google虽然暴露了这个方法,但是他本身是不建议这样设置的,以下是google的描述:

However, the ability to request a large heap is intended only for a small set of apps that can justify the need to consume more RAM
 (such as a large photo editing app). Never request a large heap simply because you’ve run out of memory and you need a quick fix
—you should use it only when you know exactly where all your memory is being allocated and why it must be retained. Yet, even 
when you’re confident your app can justify the large heap, you sho
  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值