I want to know the number of incoming transactions with value required for one outgoing transaction in order to estimate the transaction costs.
How can I detect when a transaction has been spent and has become valueless?
Use the following format:
If you don't see the outputs there, then it's spent (valueless according to your words) and at the same time, you can estimate the needed inputs for your "outgoing transaction".
Don't forget to factor in transaction fee as well.
Take note that what "mocacinno" mentioned earlier still applies:
it's possible your wallet generated change addresses, so you might have change addresses you did not manually create, but still belonging to your wallet containing unspent outputs.