Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Resource leakages  RSS feed

 
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
 
Sheriff
Posts: 4737
131
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.
 
Saloon Keeper
Posts: 8580
161
  • 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.
 
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
 
Marshal
Posts: 58321
178
  • 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
 
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.
 
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.
 
Bartender
Posts: 3306
86
  • 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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!