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: 
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`
add Log.debug() in listener to ensure the remove position is right.

How do you know after click,the last item is removed?I mean,if there has text label in item view?Maybe you remove the right item,but after gridview refresh,it looks like the last item is removed.

You can add position label with setText in getView.That may helps you.

Ok,I know.Where did you do render item view?You must do it in getView.The AdapterView cached it's item view.As you removed the right position.May be the position is not the right view.You can run hierarchyviewer to detect what happen.