473,666 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JavaMail POP Issue - memory leak

I'm finding that as I loop through a large pop store and reading each
message into an input stream that the JVM is running out of memory for the
case where the pop store is large (several thousand messages). I've run
this code through JProbe and found that InternetHeaders seems to be the
culprit as the memory heap grows over time for this class but for the life
of me I can't figure out how to get the objects freed up for garbage
collection.

Any hints as to how to avoid this problem? I'm currently using
j2sdk1.4.0_02, javamail-1.3, and jaf-1.0.2

Code follows:
import java.io.*;
import java.util.*;
import javax.mail.*;
import java.sql.*;

public class popParse {

private static String host;
private static String mailAccountName ;
private static String mailAccountPass ;
private static Session mSession;

public static void main (String args[]){
host = args[0];
mailAccountName = args[1];
mailAccountPass = args[2];

// Get session
mSession = Session.getInst ance(new Properties(), null);

checkAccount(ma ilAccountName,m ailAccountPass) ;

}
private static void checkAccount(St ring aUserName, String aPassword){

try{

// Get the store
Store store = mSession.getSto re("pop3");
store.connect(h ost, aUserName, aPassword);

// Get folder
Folder folder = store.getFolder ("INBOX");
folder.open(Fol der.READ_WRITE) ;

for (int i=0; i<len; i++) {
Message msg = folder.getMessa ge(i+1);
try{
InputStream is = msg.getInputStr eam();

// rest of parsing routine goes here... truncated for
example only

is.close();
is = null;
msg = null;

}catch(IOExcept ion e){
System.out.prin tln(e.getMessag e());
}catch(Messagin gException e){
System.out.prin tln(e.getMessag e());
}catch(Exceptio n e){
System.out.prin tln(e.getMessag e());
}
} // end of for loop over all messages

}catch(NoSuchPr oviderException e){
System.out.prin tln(e.getMessag e());
}catch(Messagin gException e){
System.out.prin tln(e.getMessag e());
}
}
}
Jul 17 '05 #1
1 4687
Perhaps the wrong way of looking at the problem but you could always
allocate more memory to the Virtual Machine as you execute your program. I
think it's an option setting for the command line that points to your class.

//Simon
"Jeff" <ju*********@co x.net> skrev i meddelandet
news:RQ6Vc.5537 $016.2332@fed1r ead01...
I'm finding that as I loop through a large pop store and reading each
message into an input stream that the JVM is running out of memory for the
case where the pop store is large (several thousand messages). I've run
this code through JProbe and found that InternetHeaders seems to be the
culprit as the memory heap grows over time for this class but for the life
of me I can't figure out how to get the objects freed up for garbage
collection.

Any hints as to how to avoid this problem? I'm currently using
j2sdk1.4.0_02, javamail-1.3, and jaf-1.0.2

Code follows:
import java.io.*;
import java.util.*;
import javax.mail.*;
import java.sql.*;

public class popParse {

private static String host;
private static String mailAccountName ;
private static String mailAccountPass ;
private static Session mSession;

public static void main (String args[]){
host = args[0];
mailAccountName = args[1];
mailAccountPass = args[2];

// Get session
mSession = Session.getInst ance(new Properties(), null);

checkAccount(ma ilAccountName,m ailAccountPass) ;

}
private static void checkAccount(St ring aUserName, String aPassword){

try{

// Get the store
Store store = mSession.getSto re("pop3");
store.connect(h ost, aUserName, aPassword);

// Get folder
Folder folder = store.getFolder ("INBOX");
folder.open(Fol der.READ_WRITE) ;

for (int i=0; i<len; i++) {
Message msg = folder.getMessa ge(i+1);
try{
InputStream is = msg.getInputStr eam();

// rest of parsing routine goes here... truncated for
example only

is.close();
is = null;
msg = null;

}catch(IOExcept ion e){
System.out.prin tln(e.getMessag e());
}catch(Messagin gException e){
System.out.prin tln(e.getMessag e());
}catch(Exceptio n e){
System.out.prin tln(e.getMessag e());
}
} // end of for loop over all messages

}catch(NoSuchPr oviderException e){
System.out.prin tln(e.getMessag e());
}catch(Messagin gException e){
System.out.prin tln(e.getMessag e());
}
}
}

Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3634
by: Elbert Lev | last post by:
#When I'm running this script on my windows NT4.0 box, #every time dialog box is reopened there is memory growth 384K. #Bellow is the text I sent to Stephen Ferg (author of easygui) # I have tested the pure Tkinter, # by modifiing on of the examples in the distribution. # This little guy also exibits the same behaviour. # Namely: every time the window is closed and reoppend, # there is memory leak of several hundreds 384K
8
3408
by: ranjeet.gupta | last post by:
Dear All Is the Root Cause of the Memory corruption is the Memory leak, ?? suppose If in the code there is Memory leak, Do this may lead to the Memory Corruption while executing the program ? In nut shell, what is/are the realtion/s between the Memory Leak and Memory Corruption. Juts Theoritical Assumtion below:
17
4798
by: José Joye | last post by:
Hi, I have implemented a Service that is responsible for getting messages from a MS MQ located on a remote machine. I'm getting memory leak from time to time (???). In some situation, it is easier to reproduce (e.g.: remote machine not available). After about 1 day, I get a usage of 300MB of memory. I have used .NET Memory Profiler tool to try to see where the leak is located. For all the leaky instances, I can see the following (I...
4
6078
by: Don Nell | last post by:
Hello Why is there a memory leak when this code is executed. for(;;) { ManagementScope scope = new ManagementScope(); scope.Options.Username="username"; scope.Options.Password="password"; scope.Path.Path=@"\\pc\root\cimv2";
20
8092
by: jeevankodali | last post by:
Hi I have an .Net application which processes thousands of Xml nodes each day and for each node I am using around 30-40 Regex matches to see if they satisfy some conditions are not. These Regex matches are called within a loop (like if or for). E.g. for(int i = 0; i < 10; i++) { Regex r = new Regex();
23
4545
by: James | last post by:
The following code will create memory leaks!!! using System; using System.Diagnostics; using System.Data; using System.Data.SqlClient; namespace MemoryLeak
3
5311
by: Jim Land | last post by:
Jack Slocum claims here http://www.jackslocum.com/yui/2006/10/02/3-easy-steps-to-avoid-javascript- memory-leaks/ that "almost every site you visit that uses JavaScript is leaking memory". Anybody know anything about this? Does *Javascript* leak memeory, or does the *browser* leak memory?
7
15693
by: Ragnar Agustsson | last post by:
Hi all I have been wandering about the best way to sandbox memory leaks in 3rd party libraries when using them from the .Net framework. I have a 3rd party library, written in C++, that leaks a lot of memory but I still had to use it. 1. After using DLLImport and seeing the memory leak I tried to load and
22
9332
by: Peter | last post by:
I am using VS2008. I have a Windows Service application which creates Crystal Reports. This is a multi theaded application which can run several reports at one time. My problem - there is a memory leak someplace. I can not detect the memory leak by running several reports by hand, but when I run tha app as a servrice and process few hundred reports there is significant memory leak. The application can consume over 1GB of memory where it...
0
8876
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8556
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8642
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2774
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1777
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.