| Weird problem/observation with Sequence remove() [message #872040] |
Tue, 15 May 2012 07:04  |
Maarten Bezemer Messages: 66 Registered: February 2012 |
Member |
|
|
Hi,
I noticed something really strange and am unsure what to do with it.
A simple representation of the problematic code (including my bug):
var index = 0;
while(index < list.size()) {
var item = list.get(index);
if(not item.allowProcess()) {
index = index + 1;
continue;
}
list.remove(index);
index = 0;
-- Process item and generate code (but absolutely not using list anymore!)
}
Note: that list (Sequence) dot not contain numbers/integers but a certain selection of the objects (extending EObject) of the model. The list got filled with something like diagram.getObjects().select(d|d.shouldSelect()).
The observant reader should notice the bug by now: list.remove(index) should have been list.removeAt(index).
So far so good.
My actual problem is that the example code did work for weeks!
A Windows user finally got an OutOfMemory error as item was processed a infinite amount of times. As it should be due to the bug.
All Mac and Linux users (including myself) did not experience any problems. Processing with large or small lists does not seem to matter.
Personally, I got really surprised by this!
So, the reason of this post: is the a known problem/bug? Are there differences between Windows and other OSes at all? (with respect to Epsilon of course )
As I am kind of busy with deadlines, I did not yet have time to create a minimal example. If this is desired (because of the weirdness of this problem), please let me know and I'll try to make time for this.
[Updated on: Tue, 15 May 2012 07:07] Report message to a moderator
|
|
|
|
| Re: Weird problem/observation with Sequence remove() [message #872078 is a reply to message #872057] |
Tue, 15 May 2012 08:19   |
Maarten Bezemer Messages: 66 Registered: February 2012 |
Member |
|
|
Hello Antonio,
Thanks for your detailed explanation. I am not storing integers in the collection, but other from this the problem is exactly as your describe.
As I noted earlier, I switched to removeAt() to remove a certain index (as I should have used from the start). So for this particular situation it is solved for me.
Only problem is that I do not know for sure, whether I did make this mistake in other places as well, which are 'accepted' because I develop and test under Linux.
So it is not a showstopper, but until yesterday I thought my code was ok. Now I need to check for remove() occurrences and verify they are correct... 
For the short term, a notice about this known issue, to warn (future) developers to be careful, in the documentation is good enough I suppose.
On the longer run, this definitely needs to be fixed of course.
Maarten
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.01564 seconds