I'm writing a chess engine in Java and using bitboards to represent the board (12 64-bit numbers). The size of an instance of this class(its retained size) is 152Bytes according to IntelliJ debugger. When trying to see a few moves a head, for each move I consider I create a new instance to represent the new Board state. Below is what the Board class looks like approximately.
public long WP=0L, WN=0L, WB=0L, WR=0L, WQ=0L, WK=0L, BP=0L, BN=0L, BB=0L, BR=0L, BQ=0L, BK=0L;
long NOT_WHITE_PIECES;
long WHITE_PIECES;
long BLACK_PIECES;
long OCCUPIED;
long EMPTY;
public void updateBitboards() {}
public void updateMailbox() {}
public void movePiece(Move move) {}
public void drawBitboard() {}
Other fields and methods are static so I don't think they affect the size of an instance. The problem is, even if I want to consider only the first 4 moves in chess, there's ~8,000,000 possible combination of moves. So I'm going to end up storing a total of 8,000,000*152B = 1,216,000,000B... which is 1.2GB.
I feel like I'm missing something here. How can I increase the number of positions I consider at a time?
First, you don't want to create a new instance of the board state each move. If you are using e.g. Minimax then you make the move, make recursive call, then unmake the move. This way you always just have one board state which it considers.
Then to minimize the number of moves you need to consider you want to make enhancements to the algorithm. The most common to start with is alpha-beta pruning which you can read more about here: https://www.chessprogramming.org/Alpha-Beta. Alpha beta pruning will always yield the same result as a minimax, but you consider less positions since you don't search the hopeless ones.
Then there are tons of other pruning techniques that you can do to reduce the search tree. Most of these will not yield the same result since you "manually" choose to cut off certain positions that you "think" is going to be bad. This could be things like the assumption that there is always better to do something than nothing (null move pruning).
Other easy things you can do to speed up algorithm is to look at move ordering. To make Minimax most efficient you always want to look at the best move first in each position. That way you will get more cutoffs and not search as many moves. Everything you need to know about chess programming you can find at https://www.chessprogramming.org/.