How to check if Pickable is still valid

Tried digging in the docs, but I couldn’t find a way. Suppose I have a list of Pickable items and I went to grab one of them. If while running, the item either de-spawed or was picked up by another player before the player got there, how can I query if the Pickable I have targeted is still valid? So far I’m thinking I’ll have to use the item table listener and give up after x time if I don’t get an event for that item, but it would be nice if you could do something like pickable.existsInWorld()

simply null check the pickable

Will that work though? I’m at work so I can’t try for a couple hours, but in my mind it won’t work? It’s been ages since I used Java but I’m pretty sure as long as I have a reference to the Pickable, even if it goes out of scope for RSPeer the GC won’t run because I still have a reference, so the value won’t go null?

As far as I know you can’t explicit de-allocate memory in Java and if you could all I would have is a dangling pointer, I could be wrong though, as I said it’s been a while since I used Java.

Null check against pickable works fine for me

If I do

Pickable[] items = Pickables.getLoaded();

And lets say I have a separate class MyPickablesClass that among other things stores a list of Pickables.

If perform some logic and store some of them into an instance of MyPickablesClass for later use. In my tests they do not seem to go null after picking them up the item, which in my mind is expected behavior. I might be doing something wrong so I’ll play around with it.

yeah you should probably not do it like that and instead define the items array inside your loop so it gets updated constantly

check out some open source examples and you’ll figure it out

I was refreshing my list periodically, but I’m grouping and sorting the items based on criteria and then operating on those results. For now I just made it refresh every loop, but it’s causing some slight performance issues(Which can be optimised) as it’s doing quite some work. The results shouldn’t change often so being able to cache my results would be nice and then check if they are still valid when I need to operate on a specific item. The problem is my situation isn’t the typical way you would use Pickables.