This thread is archived
4 Replies Last post: Sep 24, 2005 6:27 PM by Karl  
Karl Bronze 43 posts since
Jul 12, 2005
Currently Being Moderated

Sep 23, 2005 9:00 AM

OutOfMemoryError: PacketCollector issues?

Hey everyone.

 

Here''s what I keep getting:

Exception in thread "Smack Packet Writer" java.lang.OutOfMemoryError: Java heap space

 

And my code was as follows, surrounded by a while(true) loop:

 


this.packetCollector = this.xmppConnection.createPacketCollector(new PacketTypeFilter(IQ.class));
Packet receivedPacket = this.packetCollector.nextResult(timeoutMsec);

 

After doing some searching through the forums, I found out that I was forgetting to cancel() my PacketCollector''s.  So my code became:

 


this.packetCollector = this.xmppConnection.createPacketCollector(new PacketTypeFilter(IQ.class));
Packet receivedPacket = this.packetCollector.nextResult(timeoutMsec);
this.packetCollector.cancel();

 

However, I still get the OutOfMemoryError''s.  Anyone have any ideas?  Thanks!

Alex Wenckus Jiver 1,029 posts since
Jan 13, 2005
Currently Being Moderated
Sep 23, 2005 9:10 AM in response to: Karl
Re: OutOfMemoryError: PacketCollector issues?

you said it was surrounded by a while loop? you don''t need to create a new PacketCollector everytime, once should do it.

Alex Wenckus Jiver 1,029 posts since
Jan 13, 2005
Currently Being Moderated
Sep 23, 2005 10:18 AM in response to: Karl
Re: OutOfMemoryError: PacketCollector issues?

do:

 


Packet receivedPacket;

 

outside of the while loop

 

and


receivedPacket = this.packetCollector.nextResule(timeoutMsec);

 

inside. I don''t think that is your problem but it might help. Are you doing anything else in the loop? Are you putting those packets into a collection or anything? What are you doing with receivedPacket?

 

Out of memory errors are deceptive in that the stack traces generally don''t point to the source of the problem. What''s happening is that objects are being kept in memory , there are references to them and they cannot be garbage collected, and the jvm is running out of memory. If I can get a little more contextual information, I could perhaps figure out where your program is failing.

More Like This

  • Retrieving data ...