• Post Reply Bookmark Topic Watch Topic
  • New Topic

Resource leakages  RSS feed

 
shiva kore
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
According to me these are some reasons for resource leakages could you please add few more resource leakages if I have missed out:-

1) If we forget to close connection
2) If we forget to close file
3) if we write update query in infinite loop
4) if we are trying to write file where is no disk space
 
Knute Snortum
Sheriff
Posts: 4270
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know if you want specifically resource leaks, but a source of memory leaks is when you are no longer using an object and you keep a reference to it. It can never be garbage-collected in this instance.
 
Stephan van Hulst
Saloon Keeper
Posts: 7963
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see how the last two would give you a resource leak in general.

In general, I would say resource leaks occur when you don't close AutoCloseables, and memory leaks occur when you keep unused references in (static) fields.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I recall, if you are doing any work with images / graphics contexts you may hang on to system resources if you do not correctly dispose()

See the java.awt.Graphics JavaDocs and the dispose() method discussion.

Bill
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried googling for lists of why you might suffer a resource leak or a memory leak and they were surprisingly difficult to find
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:I tried googling for lists of why you might suffer a resource leak or a memory leak and they were surprisingly difficult to find


I like the irony of that since memory leaks themselves are often difficult to find. Especially in JavaScript.
 
Mike Degteariov
Ranch Hand
Posts: 145
8
Java Mac MySQL Database Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another kind of resource leak worth mentioning is a thread leak.

It happens when an application starts spawning threads in uncontrollable manner, usually in response to requests coming from outside.
This could be the case when threads are not being taken from a fixed size connection pool, but rather get created as new Thread(runnable) on demand.

This will always result to a memory leak (simply because the thread class takes space in memory), and depending to the nature of the task the thread implements it can also lead to uncontrollable growth of usage of another kind resources, which could be database connections, http connections, open files, and so on.
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Degteariov wrote:Another kind of resource leak worth mentioning is a thread leak.

It happens when an application starts spawning threads in uncontrollable manner, usually in response to requests coming from outside.
This could be the case when threads are not being taken from a fixed size connection pool, but rather get created as new Thread(runnable) on demand.

This will always result to a memory leak (simply because the thread class takes space in memory), and depending to the nature of the task the thread implements it can also lead to uncontrollable growth of usage of another kind resources, which could be database connections, http connections, open files, and so on.

Spawning more and more threads isn't a memory leak, it is memory usage. It only becomes a memory leak when you lose the ability to terminate them (and/or they don't self terminate) and so the garbage collector can't reuse the memory they are using.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!