Question: I have a background thread that is querying an Oracle database via a Select statement. The statement is populating a ResultSet Java object. If the query returns a lot of rows, the ResultSet object might get very large. If it's too large, I want to both cancel the background thread, but more importantly I want to cancel the thread that is creating the ResultSet object and eating up a lot of Java memory.

From what I have read so far online, `java.sql.Statement cancel()`, seems to be the best way to get this done, can anyone confirm this? is there a better way?

`java.sql.Statement close()` also works, I could probably catch the ExhaustedResultset exception, but maybe that's not safe.

To clarify, I do not want the ResultSet or the thread - I want to discard both completely from memory.

Answer: 
You have ImageButton's in every item right? You can set

```
holder.close.setTag(Integer.valueOf(position));

```

And then, you have all positions hidden in the right buttons.Change the OnClickListener like below:

```
close.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View v)
        {
            list.remove((Integer) v.getTag()); 
            adapter.notifyDataSetChanged();
        }
    });

```
Please use ViewHolder pattern, and also add your gridMain\_text.xml 
else you will keep receiving wrong index of click
<http://www.binpress.com/tutorial/smooth-out-your-listviews-with-a-viewholder/9>
This is example of ListView but equally applicable for `GridView`