{"action":"created","issue":{"url":"https://api.github.com/repos/google/guava/issues/1960","labels_url":"https://api.github.com/repos/google/guava/issues/1960/labels{/name}","comments_url":"https://api.github.com/repos/google/guava/issues/1960/comments","events_url":"https://api.github.com/repos/google/guava/issues/1960/events","html_url":"https://github.com/google/guava/issues/1960","id":56284246,"number":1960,"title":"ImmutableList.iterator() shouldn't retain a reference to the ImmutableList","user":{"login":"dbentley","id":159980,"avatar_url":"https://avatars.githubusercontent.com/u/159980?v=3","gravatar_id":"","url":"https://api.github.com/users/dbentley","html_url":"https://github.com/dbentley","followers_url":"https://api.github.com/users/dbentley/followers","following_url":"https://api.github.com/users/dbentley/following{/other_user}","gists_url":"https://api.github.com/users/dbentley/gists{/gist_id}","starred_url":"https://api.github.com/users/dbentley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbentley/subscriptions","organizations_url":"https://api.github.com/users/dbentley/orgs","repos_url":"https://api.github.com/users/dbentley/repos","events_url":"https://api.github.com/users/dbentley/events{/privacy}","received_events_url":"https://api.github.com/users/dbentley/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-02-02T19:52:02Z","updated_at":"2015-02-02T20:32:35Z","closed_at":null,"body":"This is a feature request where the cost may far outweigh the benefit, and I understand that, but I ran into it and think it would be right in principle, if difficult in practice.\r\n\r\nConsider the following code:\r\n\r\nIterator<Bar> deserialize(DatabaseConnection conn) {\r\n  return Iterators.transform(conn.fetch(), new Function<Foo, Bar>() {\r\n    @override public Bar apply(Foo foo) {\r\n      Bar.deserialize(foo);\r\n    }});\r\n}\r\n\r\nContext:\r\n1) conn.fetch() returns an ImmutableList<Foo>\r\n2) Foo is the serialized form (perhaps a protobuf) of a record, and Bar is the POJO form.\r\n3) A Foo is smaller than a Bar, so you can keep ImmutableList<Foo> in memory, but you can't keep an ImmutableList<Foo> in memory while you operate on each Bar.\r\n\r\nThe result is that, instead, we copy the ImmutableList into an array and then create an Iterator that in each call to next() nulls out that slot in the array.\r\n\r\nIt would be awesome if ImmutableList's Iterator allowed earlier elements in the list to be garbage."},"comment":{"url":"https://api.github.com/repos/google/guava/issues/comments/72531934","html_url":"https://github.com/google/guava/issues/1960#issuecomment-72531934","issue_url":"https://api.github.com/repos/google/guava/issues/1960","id":72531934,"user":{"login":"lowasser","id":544569,"avatar_url":"https://avatars.githubusercontent.com/u/544569?v=3","gravatar_id":"","url":"https://api.github.com/users/lowasser","html_url":"https://github.com/lowasser","followers_url":"https://api.github.com/users/lowasser/followers","following_url":"https://api.github.com/users/lowasser/following{/other_user}","gists_url":"https://api.github.com/users/lowasser/gists{/gist_id}","starred_url":"https://api.github.com/users/lowasser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lowasser/subscriptions","organizations_url":"https://api.github.com/users/lowasser/orgs","repos_url":"https://api.github.com/users/lowasser/repos","events_url":"https://api.github.com/users/lowasser/events{/privacy}","received_events_url":"https://api.github.com/users/lowasser/received_events","type":"User","site_admin":false},"created_at":"2015-02-02T20:32:35Z","updated_at":"2015-02-02T20:32:35Z","body":"As mentioned above, a queue seems more like what you're looking for?  Queues *expect* to have an element consumed once and never used again."}}