6. On a $999 \times 999$ grid, there is a lame bird that moves according to the following rules: from the center of any cell to the center of any adjacent cell (cells that share a common edge), each move must turn, meaning that any two consecutive moves must be perpendicular. A non-intersecting path of the lame bird refers to the centers of the cells it passes through, all of which are distinct. If the lame bird can directly move from the center of the last cell of this path to the center of the first cell of this path, then this non-intersecting path is called "closed". How many cells does the longest closed, non-intersecting path of the lame bird pass through?
6. $998^{2}-4=4\left(499^{2}-1\right)$ squares.

First, prove: This number is the upper bound of the number of squares the lame bird can pass through.

Let the center of the square in the $i$-th row and $j$-th column be denoted as $(i, j)$. Color the squares with four colors $A, B, C, D$ as follows:

If $(i, j) \equiv (0,0) \pmod{2}$, then color the square centered at $(i, j)$ as $A$;

If $(i, j) \equiv (0,1) \pmod{2}$, then color the square centered at $(i, j)$ as $B$;

If $(i, j) \equiv (1,0) \pmod{2}$, then color the square centered at $(i, j)$ as $C$;

If $(i, j) \equiv (1,1) \pmod{2}$, then color the square centered at $(i, j)$ as $D$.

The lame bird can only move from a square of color $A$ to a square of color $B$ or $C$.

In the first case, the sequence of colors the lame bird passes through is:
$A, B, D, C, A, B, D, C, A, \cdots$;
In the second case, the sequence of colors the lame bird passes through is:
$A, C, D, B, A, C, D, B, A, \cdots$.
By symmetry, we only need to discuss the first case.
Since the path is closed and the number of squares of each color is the same, there are $499^{2}$ squares of color $A$.

Next, prove: The lame bird cannot pass through all squares of color $A$.

Under this conclusion, the path that satisfies the condition contains at most $4(499^{2}-1)$ squares.

Assume there is a path that passes through all squares of color $A$. Color the squares of color $A$ in a checkerboard pattern, i.e., any two centers with a distance of 2 and of color $A$ are colored differently. Since the number of squares of color $A$ is odd, the lame bird cannot always alternate between black and white along this path. Therefore, there exist two squares of the same color that are initially of color $A$, such that one can reach the other in 4 steps. Assume these two squares are $(a, b)$ and $(a+2, b+2)$.

As shown in Figure 1, the path from $(a, b)$ to $(a+2, b+2)$ is unique, which can be:
$(a, b) \rightarrow (a, b+1) \rightarrow (a+1, b+1) \rightarrow (a+1, b+2) \rightarrow (a+2, b+2)$.
Thus, the color of $(a, b+1)$ is $B$.
Next, consider the square of color $A$ at $(a, b+2)$.
In the first case, the lame bird must pass through $B$ after passing through $A$, so the path through $(a, b+2)$ must be:
$(a-1, b+2) \rightarrow (a, b+2) \rightarrow (a, b+3)$.
Therefore, the path connecting these two segments must be the path connecting $(a, b+3)$ and $(a, b)$, and the path connecting $(a+2, b+2)$ and $(a-1, b+2)$. However, the centers of these four unit squares form the vertices of a convex quadrilateral, and the path is outside this quadrilateral, so these two paths must intersect.
Thus, we can conclude:
The path connecting $(a, b+3)$ and $(a, b)$, together with the line segment connecting these two points, forms a closed loop, with $(a-1, b+2)$ and $(a+2, b+2)$ on opposite sides of this loop. Therefore, the path connecting these two points must cross the previous closed loop, meaning the intersection point is passed through twice, which is a contradiction.

Therefore, the maximum number of squares the lame bird can pass through is $4(499^{2}-1)$.

Second, provide an example of a path that passes through exactly $4(499^{2}-1)$ squares.

The following Figure 2 shows that for $n \equiv 3 \pmod{4}$, an $n \times n$ chessboard can be constructed recursively to form a path that satisfies the condition and exactly does not pass through one square of color $A$ (Figure 2 shows a $15 \times 15$ chessboard, with the center of the black dot being the square of color $A$ that is not passed through).

Thus, when $n=999$, this path passes through exactly $4(499^{2}-1)$ squares.