首页 \ 问答 \ 为什么在android上自动释放这个内存?(Why automatically released this memory at android?)

为什么在android上自动释放这个内存?(Why automatically released this memory at android?)

关于我的android appwiget,我有一些内存问题,(这是基于可绘制动画重复的小玩具appwidget)

所以我在Android Studio中观看了我的内存查看器。

我发现我的应用程序的内存在初始时间增加了,但是当内存不足时它会自动释放一些内存。

  1. 我想知道android函数是做什么的。

  2. 我可以用java代码控制这个发布功能吗?

*我在真实设备android ver 4.42测试


I have some memory problems about my android appwiget, (It's small toy appwidget based drawable animation repeat)

So I watched my memory viewer in Android Studio.

I found my app's memory increased at initial time, but when it doesn't enough memory it automatically release some memory.

  1. I want to know what android function make this.

  2. Can I control this release function with java code?

*I tested at real device android ver 4.42


原文:https://stackoverflow.com/questions/31853165
更新时间:2022-11-15 13:11

最满意答案

在问题的第一部分,for comprehension实现将范围0 to l.length-1i1+1 to l.length-1IndexedSeq[Int]因此所产生的类型是特征IndexedSeq[(Int, Int)]由最终的类Vector

在第二部分中,您的方法是有效的,但在不使用对列表的索引引用的情况下,

for (List(a,b,_*) <- xs.combinations(2).toList) yield (a,b)

注意

xs.combinations(2).toList
List(List(4, 3), List(4, 2), List(4, 1), List(3, 2), List(3, 1), List(2, 1))

所以使用List(a,b,_*)我们模式匹配并提取每个嵌套列表的前两个元素( _*表示忽略可能的附加元素)。 由于迭代在列表上,理解产生一个双列表。


On the first part of the question, the for comprehension implementation defines ranges 0 to l.length-1 and i1+1 to l.length-1 as IndexedSeq[Int] hence the yielded type is trait IndexedSeq[(Int, Int)] implemented by final class Vector.

On the second part, your approach is valid, yet consider the following where we do not use indexed references to the lists,

for (List(a,b,_*) <- xs.combinations(2).toList) yield (a,b)

Note that

xs.combinations(2).toList
List(List(4, 3), List(4, 2), List(4, 1), List(3, 2), List(3, 1), List(2, 1))

and so with List(a,b,_*) we pattern-match and extract the first two elements of each nested list (the _* indicates to ignore possible additional elements). Since the iteration is over a list, the for comprehension yields a list of duples.

相关问答

更多
  • 一些替代方案 let xs = [1..3] in [(a,b,c) | a <- xs, b <- xs, c <- xs] [(a,b,c) | let xs = [1..3], a <- xs, b <- xs, c <- xs] (,,) <$> [1..3] <*> [1..3] <*> [1..3] let xs = [1..3] in (,,) <$> xs <*> xs <*> xs (\[a,b,c]->(a,b,c)) <$> replicateM 3 [1..3] 但是,我会寻找最可 ...
  • 我在这里错过了关于Scala中List和Tuples的内容吗? 我认为Odersky试图表明的主要观点是每个元组元素都可以包含自己的单独类型,这允许使用多种不同的类型。 由于列表是同类的,因此List无法执行的操作,这意味着如果您需要List[Int] ,则该列表的所有元素都必须是Int值。 如果查看您创建的列表的类型,您将看到编译器推断List[Any] ,这是所有Scala类型的常见超类型。 这意味着如果你想用列表中的一个元素做一些具体的事情,即它是Int类型的head元素,你不能因为所有编译器都知道该 ...
  • 尝试这个 : a = [('a', 'b'), ('c', 'd'), ('a', 'b'), ('b', 'a')] b = list(set([ tuple(sorted(t)) for t in a ])) [('a', 'b'), ('c', 'd')] 我们来分解一下: 如果你对一个元组进行排序,它将变成一个排序列表。 >>> t = ('b', 'a') >>> sorted(t) ['a', 'b'] 对于a中的每个元组t ,对其a排序并将其转换回元组。 >>> b = [ tuple(s ...
  • 我做错了什么,是否有一种惯用的方式来实现这一点? 让我们一步一步看看你做错了什么 。 (我打算使用REPL ) 首先让我们定义点 scala> val points: List[(Int, Double)] = List( | (1, 1.0), | (2, 3.2), | (4, 2.0), | (1, 4.0), | (2, 6.8) | ) points: List[(Int, Double)] = List((1,1.0 ...
  • 这两种数据结构完全不同。 1. Map查找时间是O(1) 。 在列表中它将是O(n) 因此,如果您需要在您的键中查找元素 - >值映射使用map 。 scala> val myMap = Map("a" -> 1, "b" -> 2, "c" -> 3) myMap: scala.collection.immutable.Map[String,Int] = Map(a -> 1, b -> 2, c -> 3) scala> myMap.get("a") res7: Option[Int] = Some( ...
  • 我在更新问题之前开始写这个,所以这是一个没有你的how_many()函数的例子,而是一个虚函数(奇怪的是我也称之为how_many!)看看这是否有帮助...... initial_input = [("This doesn't matter", 0),("Gimme 4", 0),("Maybe 8", 0),("Ignore me", 1)] def how_many(mystring): return int(mystring[-1]) def display(yourlist): ...
  • 你可能意思是这样的: a.groupBy(_._1).mapValues(_.map(_._2)) 要么: a.groupBy(_._1).mapValues(_.unzip._2) 结果: Map(2 -> List(b, B), 1 -> List(a, A), 3 -> List(c)) You probably meant something like this: a.groupBy(_._1).mapValues(_.map(_._2)) or: a.groupBy(_._1).mapVa ...
  • 我的问题是:为什么它找到Unit而不是List? 因为 val liste = (name, age)::separate(t) 是一项任务。 如果您想要返回该值并继续执行,则赋值具有返回类型的单位 case (name, age)::t if age%2==0 => {(name, age)::separate(t)} 为了让老年人获得平衡,我建议你使用collect。 所以, val fichier : List[(String, Int)] = List(("Emma Jacobs",21), (" ...
  • 在问题的第一部分,for comprehension实现将范围0 to l.length-1和i1+1 to l.length-1为IndexedSeq[Int]因此所产生的类型是特征IndexedSeq[(Int, Int)]由最终的类Vector 。 在第二部分中,您的方法是有效的,但在不使用对列表的索引引用的情况下, for (List(a,b,_*) <- xs.combinations(2).toList) yield (a,b) 注意 xs.combinations(2).toList Lis ...
  • 使用groupBy()运算符来收集具有公共字段的元组。 下面的第一个groupBy选择前两个字段,并将它们映射到id和name Map条目。 第二个嵌套的groupBy在项目字段上进行子选择并创建项目列表。 第三次迭代现在接收与项目相关的人员。 val listOfProjectMaps = resultList.groupBy(t => (t._1, t._2)) .map({ case (k, v) => Map( "id" -> k._1, "name" -> k._2, ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)