为什么在android上自动释放这个内存?(Why automatically released this memory at android?)
关于我的android appwiget,我有一些内存问题,(这是基于可绘制动画重复的小玩具appwidget)
所以我在Android Studio中观看了我的内存查看器。
我发现我的应用程序的内存在初始时间增加了,但是当内存不足时它会自动释放一些内存。
我想知道android函数是做什么的。
我可以用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.
I want to know what android function make this.
Can I control this release function with java code?
*I tested at real device android ver 4.42
原文:https://stackoverflow.com/questions/31853165
最满意答案
在问题的第一部分,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 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
andi1+1 to l.length-1
asIndexedSeq[Int]
hence the yielded type is traitIndexedSeq[(Int, Int)]
implemented by final classVector
.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 and Tuples in Scala)[2022-09-24]
我在这里错过了关于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 ...
-
Scala元组到层次结构(Scala tuples to hierarchy)[2021-12-11]
使用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, ...