{"action":"opened","issue":{"url":"https://api.github.com/repos/milesibastos/jTDS/issues/2","repository_url":"https://api.github.com/repos/milesibastos/jTDS","labels_url":"https://api.github.com/repos/milesibastos/jTDS/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/milesibastos/jTDS/issues/2/comments","events_url":"https://api.github.com/repos/milesibastos/jTDS/issues/2/events","html_url":"https://github.com/milesibastos/jTDS/issues/2","id":148523767,"number":2,"title":"jTDS memory leak on Tomcat SQLDiagnostic lastWarning","user":{"login":"samgabriel","id":3934515,"avatar_url":"https://avatars.githubusercontent.com/u/3934515?v=3","gravatar_id":"","url":"https://api.github.com/users/samgabriel","html_url":"https://github.com/samgabriel","followers_url":"https://api.github.com/users/samgabriel/followers","following_url":"https://api.github.com/users/samgabriel/following{/other_user}","gists_url":"https://api.github.com/users/samgabriel/gists{/gist_id}","starred_url":"https://api.github.com/users/samgabriel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samgabriel/subscriptions","organizations_url":"https://api.github.com/users/samgabriel/orgs","repos_url":"https://api.github.com/users/samgabriel/repos","events_url":"https://api.github.com/users/samgabriel/events{/privacy}","received_events_url":"https://api.github.com/users/samgabriel/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-04-15T00:54:45Z","updated_at":"2016-04-15T00:54:45Z","closed_at":null,"body":"Hi There, \r\nWe use jTDS to connect to SQL Server. Our setup includes using JNDI which requires the driver classes to be in Tomcat main classloader. Upon doing some profiling and memory dumps we found in at least one case a problem with jTDS lastWarning field keeping a reference to the a SQLWarning which is holding the last stack trace which is holding a reference to the Classloader. The problem seems to be that when creating a prepared statement and having an error this error is kept. Even thought the JtdsStatement calls messages.clearWarnings() this method doesn't clear the lastWarning and lastException field. Thus the entire class loader is held in memory. \r\n\r\nThe fix should be fairly easy as SQLDiagnostic.clearWarnings should reset the other variables as well.\r\n\r\nHere is the stack from Eclipse Memory Analyzer\r\nClass Name                                                                                                                                              | Ref. Objects | Shallow Heap | Ref. Shallow Heap | Retained Heap\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\norg.apache.tomcat.util.threads.TaskThread @ 0x17d82fc0  http-apr-8080-exec-9 Thread                                                                     |            1 |          128 |               136 |        32,824\r\n'- contextClassLoader java.net.URLClassLoader @ 0x10204ce8                                                                                              |            1 |           80 |               136 |     1,155,784\r\n   '- classes java.util.Vector @ 0x103773c8                                                                                                             |            1 |           24 |               136 |       924,744\r\n      '- elementData java.lang.Object[2560] @ 0x1862e260                                                                                                |            1 |       10,256 |               136 |       924,720\r\n         '- [283] class org.apache.tomcat.jdbc.pool.interceptor.StatementCache @ 0x107fa530                                                             |            1 |           24 |               136 |           248\r\n            '- cacheSizeMap java.util.concurrent.ConcurrentHashMap @ 0x10b70138                                                                         |            1 |           64 |               136 |           168\r\n               '- table java.util.concurrent.ConcurrentHashMap$Node[16] @ 0x10b70178                                                                    |            1 |           80 |               136 |           104\r\n                  '- [0] java.util.concurrent.ConcurrentHashMap$Node @ 0x10b701c8                                                                       |            1 |           24 |               136 |            24\r\n                     '- key org.apache.tomcat.jdbc.pool.ConnectionPool @ 0x108ca8f0                                                                     |            1 |           56 |               136 |        54,472\r\n                        '- idle org.apache.tomcat.jdbc.pool.FairBlockingQueue @ 0x108caee8                                                              |            1 |           24 |               136 |        54,064\r\n                           '- items java.util.LinkedList @ 0x108caf28                                                                                   |            1 |           24 |               136 |        53,944\r\n                              '- first java.util.LinkedList$Node @ 0x203ba2c0                                                                           |            1 |           24 |               136 |        15,584\r\n                                 '- item org.apache.tomcat.jdbc.pool.PooledConnection @ 0x108caf40                                                      |            1 |           88 |               136 |        15,560\r\n                                    '- attributes java.util.HashMap @ 0x108e44a8                                                                        |            1 |           40 |               136 |        15,008\r\n                                       '- table java.util.HashMap$Node[16] @ 0x108e44d0                                                                 |            1 |           80 |               136 |        14,968\r\n                                          '- [5] java.util.HashMap$Node @ 0x10d328c0                                                                    |            1 |           24 |               136 |        14,840\r\n                                             '- value java.util.concurrent.ConcurrentHashMap @ 0x10d328d8                                               |            1 |           64 |               136 |        14,816\r\n                                                '- table java.util.concurrent.ConcurrentHashMap$Node[128] @ 0x187e06b0                                  |            1 |          528 |               136 |        14,752\r\n                                                   '- [93] java.util.concurrent.ConcurrentHashMap$Node @ 0x194fcc30                                     |            1 |           24 |               136 |           168\r\n                                                      '- val org.apache.tomcat.jdbc.pool.interceptor.StatementCache$CachedStatement @ 0x194fcc48        |            1 |           48 |               136 |           144\r\n                                                         '- delegate com.sun.proxy.$Proxy98 @ 0x194a7d78                                                |            1 |           16 |               136 |            40\r\n                                                            '- h org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport$StatementProxy @ 0x194a7d88|            1 |           24 |               136 |            24\r\n                                                          **     '- delegate net.sourceforge.jtds.jdbc.JtdsPreparedStatement @ 0x194a7da0                 |            1 |          120 |               136 |        71,056\r\n                                                                  '- messages net.sourceforge.jtds.jdbc.SQLDiagnostic @ 0x194b0218                      |            1 |           32 |               136 |         1,048\r\n                                                                     '- lastWarning java.sql.SQLWarning @ 0x194b0238                                    |            1 |           40 |               136 |         1,016\r\n                                                                        '- backtrace java.lang.Object[4] @ 0x194b0260                                   |            1 |           32 |               136 |           800\r\n                                                                           '- [2] java.lang.Object[32] @ 0x194c0b88                **                     |            1 |          144 |               136 |           144\r\n                                                                              '- [21] class com.actbig.datahandler.service.DBService @ 0x14392ee0       |            1 |           24 |               136 |            24\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n"}}